Extends is inherited from a class, can use the parent class's methods after inheritance, or you can override the parent class's methods, inheriting the parent class, as long as the class is not declared final or the class is defined as abstract to inherit
Implements is to implement a plurality of interfaces, the method of the interface is generally empty, must be rewritten to use, you can effectively, the implementation of the class method name, and parameters are constrained. Can be alternative to the implementation of multiple inheritance.
The method body is implemented in class A extends B implements c,d,e{} class. A interface can extends multiple other interface.
Interface abc{
Const BBQ = 321;
Public Function A1 (show $ACC);
}
Class Test implements abc{
Public Function A1 (show $ACC) {//must function and parameter
return 123;
}
}
$n = new ABC ();
echo $n->a1 ();
Interface Comparable {
function compare (self $compare);
}
Class String implements comparable {
Private $string;
function __construct ($string) {
$this->string = $string;
}
function compare (self $compare) {
if ($this->string = = $compare->string) {
return $this->string. " = = ". $compare->string." <br> ";
}else{
return $this->string. "! = ". $compare->string." <br> ";
}
}
}
Class Integer implements comparable {
Private $integer;
function __construct ($int) {
$this->integer = $int;
}
function compare (self $compare) {
if ($this->integer = = $compare->integer) {
return $this->integer. " = = ". $compare->integer." <br> ";
}else{
return $this->integer. "! = ". $compare->integer." <br> ";
}
}
}
$first _int = new Integer (3);
$second _int = new Integer (4);
$first _string = new String ("foo");
$second _string = new String ("bar");
echo $first _int->compare ($second _int); 3!=4
echo $first _int->compare ($first _int); 3==3
echo $first _string->compare ($second _string); Foo!=bar
echo $first _string->compare ($second _int); Critical Error
Implement is used to extend the use of methods.
Extend the new function
var a=function () {};
var b=function () {};
Function.implement ({
Alert:function (msg) {//Direct alert output content
Alert (msg);
},
Output:function (msg) {//firebug console will output content, IE will error
Console.log (msg);
}
});
A.alert (' 1 ');
A.output (' 2 ');
B.output (' 3 ');
PHP interface, extends,implement,implements function and difference collection and collation