PHPインタフェース向けプログラミング結合設計モードの簡単な例

2077 ワード

 
  
interface js{
function ys($a,$b);
}
class Af implements js{
function ys($a,$b){
return " ...... :".($a+$b);
}
}
class Jf implements js{
function ys($a,$b){
return " ...... :".($a-$b);
}
}
class AAf implements js{
function ys($a,$b){
return " ...... :".($a*$b);
}
}
class JJf implements js{
function ys($a,$b){
return " ...... :".($a/$b);
}
}
class Modf implements js{
function ys($a,$b){
return " ...... :".($a % $b);
}
}
class China implements js{
public $varl=null;// :public $varl = new nothingx(); 。
function __construct(){
$this->varl = new nothingx();
}
function ys($a,$b){
return $this->varl->say();
}
}
/* :
class China extends nothingx implements js{
function ys($a,$b){
return parent::say();
}
}
*/
class nothingx{
function say(){
return " ... ‘ '... ......";
}
}
class test{
private $one;
private $two;
public function __construct($x,$y){
$this->one=$x;
$this->two=$y;
echo " ――
Class test :
\$one=".$this->one."   \$two=".$this->two."
";
}
function display(js $a){
return " PHP ―― :
".$a->ys($this->one,$this->two)."
";
}
}
$t=new test(103,2);
$t1=new jf;
$t2=new China;
echo $t->display($t1);
echo $t->display($t2);
?>