Just learn some of the advanced PHP, the first encounter PHP interface problem, is very puzzled.
1<?PHP2 Interfaceicaneat () {3Piblicfunctioneat ();4}://defines an interface that can be associated with a class that does not require the content implementation of the method defined5 classHuman Implement icaneat{6 Public functionEat ($food){7 Echo"Human is eating".$food;8}//A class must implement the method defined inside if it is associated with an interface. 9 }Ten $obj=NewHuman (); One?>
The above is a shorthand code. It now seems that its main use is to standardize code and to facilitate the development of many people in large-scale development.
It also involves a polymorphic feature, an important feature in object-oriented. That is, the interface is actually a rule on the class, since you this class and I related, spicy, you have to follow my rules. In the development of many people, we need to set a framework, norms and the like. But the method is not limited. That means you have to define my method, but how to do it, you think.
Classes related to the same interface, using their interface-defined methods, but are different implementations, which is polymorphic, that is, the same code, different implementations. This is the characteristic of polymorphism.
Well, first write so much, I am still a slag, the content is very rookie, the expression is also very rotten, I hope you have a lot of advice, thank you!
Some thoughts on the beginner PHP interface