<?php
abstract class PubAction
{
abstract public function index();
public function demo(){
}
}
class A extends PubAction
{
public function index()
{
return "我是A中的方法";
}
}
class B extends PubAction
{
public function index()
{
return "我是B中的方法";
}
}
class Factory
{
public static function index($str)
{
if($str == "A")
{
return new A;
}else if($str == "B")
{
return new B;
}else{
return "没有此类";
}
}
}
$obj = Factory
::index("A");
if(is_object($obj)){
echo $obj->index();
}else{
echo $obj;
}
转载请注明原文地址: https://lol.8miu.com/read-2330.html