1.php interface class: interface
In fact, their role is very simple. When many people develop a project together, they may all call some classes written by others. Then you may ask, how do I know how to name the implementation method of a certain function? Yes, at this time the php interface class comes into play. When we define an interface class, the methods in it must be implemented by the following subclasses, such as:
Conclusion: The interface class is the leader of a class, pointing out the direction. Subclasses must complete its designated methods.
2.php abstract class: abstract
In fact, abstract classes and interface classes are partially similar. I remember seeing this sentence somewhere, abstract classes extract the part of the class image. This sentence looks funny, but in fact it tells the truth of abstract classes. The role of abstract classes is that when you find that many of your classes use many methods that you keep rewriting, then you can consider using abstract classes. You may say, "I can't rewrite one class for every public class." I just instantiate this public class and call the same method." This is OK. In fact, this is what the abstract class does, but it saves you the step of instantiation, allowing you to directly It is just as convenient to call this class method, and you can also overload this method. Such as:
Conclusion: An abstract class is a service provider of a class. It has many services. You don’t have to use them. You can use them when you need them. If you feel that you don’t If you are not satisfied with the service provided, you can still do it yourself. The abstract function method is somewhat similar to the interface. It is a method declared in the parent class and must be implemented in the subclass. However, methods not declared with abstract will become public methods of the subclass. There is no need to implement them in the subclass