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
$this->two= $y;
echo "Object-oriented programming--InterfaceClass Test initialization:
Property \$ property \ $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);
?>
The above describes the JavaScript design pattern PHP interface-oriented programming coupled design pattern simple example, including the JavaScript design patterns of content, I hope to be interested in PHP tutorial friends helpful.