Copy code The code is as follows:
interface js{
function ys($a,$b );
}
class Af implements js{
function ys($a,$b){
return "Addition operation...the result is:".($a+$b );
}
}
class Jf implements js{
function ys($a,$b){
return "Subtraction operation...the result is:".( $a-$b);
}
}
class AAf implements js{
function ys($a,$b){
return "Multiplication operation...result is: ".($a*$b);
}
}
class JJf implements js{
function ys($a,$b){
return "Division operation.. ....The result is: ".($a/$b);
}
}
class Modf implements js{
function ys($a,$b){
return "Modulo operation... the result is:".($a % $b);
}
}
class China implements js{
public $varl=null;// Directly here: public $varl = new nothingx(); will go wrong.
function __construct(){
$this->varl = new nothingx();
}
function ys($a,$b){
return $this->varl ->say();
}
}
/*It can also be implemented through inheritance:
class China extends nothingx implements js{
function ys($a,$b ){
return parent::say();
}
}
*/
class nothingx{
function say(){
return "I don’t have any operations Doing...just to realize'Coupled Design Pattern'...I am here to make soy sauce..." ;
}
}
class test{
private $one;
private $two;
public function __construct($x,$y){
$this-> ;one=$x;
$this->two=$y;
echo "Object-oriented programming - interface strong>
Class test initialization:
Attribute $one=".$this->one." Attribute $two=".$this->two."
";
}
function display(js $a){
return "Computation implemented using PHP interface technology - start the calculation:< /font>
".$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);
?>
http://www.bkjia.com/PHPjc/323035.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323035.htmlTechArticleCopy the code as follows: ?php interface js{ function ys($a,$b); } class Af implements js{ function ys($a,$b){ return "Addition operation...the result is:".($a+$b); } } class Jf implementen...