For those who are beginners
In fact, their function is very simple. When many people develop a project together, they may all call some classes written by others. Then you They will ask, how do I know how to name the implementation method of a certain function? At this time, the PHP interface class interface comes into play. When we define an interface class, the method inside it is as follows: Classes must be implemented, such as:
I declare a shop interface class and define three methods: buy, sell , look (view), then all subclasses that inherit this class must implement any of these three methods. If the subclass does not implement these, it will not run. In fact, the interface class is, to put it bluntly, the template of a class and the regulations of a class. If you belong to this category, you must follow my regulations. No matter how you do it, I don’t care how you do it. That’s up to you. Things like:
<ol class="dp-xml"> <li class="alt"><span><span>class BaseShop implements Shop </span></span></li> <li><span>{ </span></li> <li class="alt"><span>public function buy($gid) </span></li> <li><span>{ </span></li> <li class="alt"><span>echo('你购买了ID为 :'.$gid.'的商品'); </span></li> <li><span>} </span></li> <li class="alt"><span>public function sell($gid) </span></li> <li><span>{ </span></li> <li class="alt"><span>echo('你卖了ID为 :'.$gid.'的商品'); </span></li> <li><span>} </span></li> <li class="alt"><span>public function view($gid) </span></li> <li><span>{ </span></li> <li class="alt"><span>echo('你查看了ID为 :'.$gid.'的商品'); </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> </ol>
Think about it, in a large project where many people are cooperating, it is so convenient to have interface classes, so that you don’t have to ask others, your What is the method name of a certain function? Of course, if you like this, I can’t help it.
Conclusion: The PHP interface class interface is the leader of a class, indicating the direction, and subclasses must complete its specified method.