<?php

/* 内容:工厂模式案例
 * @author jiqing
 * @date   2012-08-02
 */
//IUser接口
interface IUser{
    function getName();
}
//IUser接口的实现
class User implements IUser{
    public function __construct($id) {
        
    }
    public function getName() {
        return Jack;
    }
}
//UserFactory工厂类,创建IUser对象
class UserFactory{
    public static function Create($id){
        return new User($id);
    }
}
$uo = UserFactory::Create(1);
echo @$uo->getName();

?>

相关文章:

  • 2022-03-03
  • 2022-12-23
  • 2021-11-26
  • 2021-10-02
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-08-06
相关资源
相似解决方案