<?php
/**
* Created by PhpStorm.
* User: huiting
* Date: 18-3-22
* Time: 上午9:18
*/
interface IUser{
function getName();
function getAge();
}
interface IOther{
function getName();
function oindex();
}
//
class User implements IUser{
public function __construct($id)
{
$this->user_id = $id;
}
public function getName()
{
// TODO: Implement getName() method.
return 'name'.$this->user_id;
}
public function getAge(){
return 'age'.$this->user_id;
}
}
class Other implements IOther{
public function __construct($id)
{
$this->id = $id;
}
public function getName(){
return 'other'.$this->id;
}
public function oindex(){
return 'ccv';
}
}
class Factory
{
// 返回学生姓名
public static function create($id){
return new User($id);
}
// 返回其他信息
public static function other($id){
return new Other($id);
}
// 根据不同的参数实例化不同的类
public static function toClass($id,$class='Other'){
return new $class($id);
}
public function index(){
return 'cc';
}
}