Copy CodeThe 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 ... 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 China implements js{
Public $varl =null;//here directly: public $varl = new Nothingx (); Will go wrong.
function __construct () {
$this->varl = new Nothingx ();
}
Function ys ($a, $b) {
return $this->varl->say ();
}
}
/* can also be implemented in an inherited way:
Class China extends NOTHINGX implements js{
Function ys ($a, $b) {
return Parent::say ();
}
}
*/
Class nothingx{
function say () {
Return "I don't do any arithmetic ... Just to achieve
' coupling design mode '... I came out to soy sauce ... ";
}
}
Class test{
Private $one;
Private $two;
Public function __construct ($x, $y) {
$this->one= $x;
$this->two= $y;
echo "
Object-oriented programming--InterfaceClass Test initialization:
Properties \ $one = ". $this->one." Properties \ $two = ". $this->two.";
}
function display (JS $a) {
Return "
the operation implemented with PHP interface technology--begins the operation:". $a->ys ($this->one, $this->two)." ";
}
}
$t =new Test (103,2);
$t 1=new JF;
$t 2=new China;
echo $t->display ($t 1);
echo $t->display ($t 2);
?>
http://www.bkjia.com/PHPjc/323035.html www.bkjia.com true http://www.bkjia.com/PHPjc/323035.html techarticle Copy 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 Implemen ...