PHP学习之工厂方法模式
<?php //工厂方法模式 interface Doing { function eat(); function sleep(); } class Cat implements Doing { function eat() { echo '猫正在吃东西!<br />'; } function sleep() { echo '猫正在睡觉!<br />'; } } class Dog implements Doing { function eat() { echo '狗正在吃东西!<br />'; } function sleep() { echo '狗正在睡觉!<br />'; } } class Factory { static function createDoing(){} } class CatFactory implements Factory { static function createDoing() { return new Cat(); } } class DogFactory implements Factory { static function createDoing() { return new Dog(); } }