Copy Code 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 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 ... The 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 implements js{
Public $varl =null;//here directly: public $varl = new Nothingx (); There will be an error.
function __construct () {
$this->varl = new Nothingx ();
}
Function ys ($a, $b) {
return $this->varl->say ();
}
}
/* can also be implemented in an inherited way yo:
Class extends NOTHINGX implements Js{
Function ys ($a, $b) {
return Parent::say ();
}
}
*/
Class nothingx{
function say () {
Return "I do not do any operations ... Just to realize <font color= #990000 ><b> ' coupling design mode ' </b></font> .... I am out of soy sauce ... ";
}
}
Class test{
Private $one;
Private $two;
Public function __construct ($x, $y) {
$this->one= $x;
$this->two= $y;
echo "<font size=20px><strong> Object-oriented programming-interface </font></strong>}
function display (JS $a) {
Return "<font color= #990000 ><b> operations implemented using the PHP interface technology--started:</b></font>}
}
$t =new Test (103,2);
$t 1=new JF;
$t 2=new;
echo $t->display ($t 1);
echo $t->display ($t 2);
?>