<?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();
    }
}

 

相关文章:

  • 2021-04-05
  • 2021-11-24
  • 2021-12-21
  • 2021-10-25
  • 2021-06-05
  • 2021-09-09
  • 2021-08-15
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-01-03
  • 2021-07-30
  • 2021-12-19
  • 2021-11-28
相关资源
相似解决方案