<?php
interface Tell {
function call();
function receive();
}
class Xiaomi implements Tell {
function call()
{
// TODO: Implement call() method.
echo 'call sb. with xiaomi phone';
}
public function receive()
{
// TODO: Implement receive() method.
echo 'recieve from sb. with xiaomi phone';
}
}
class Motor implements Tell {
function call()
{
// TODO: Implement call() method.
echo 'motor calling';
}
function receive()
{
// TODO: Implement receive() method.
echo 'motor receiving';
}
}
interface Factory {
static function createPhone();
}
class xiaomiFactory implements Factory {
static function createPhone()
{
// TODO: Implement createPhone() method.
return new Xiaomi();
}
}
class MotorFactory implements Factory {
static function createPhone()
{
// TODO: Implement createPhone() method.
return new Motor();
}
}
php高级实战-工厂方法模式
最新推荐文章于 2024-06-14 09:22:46 发布