This article describes the principle of PHP interface isolation. Share it for your reference, as follows:
Using multiple dedicated interfaces is better than using a single total interface.
The dependence of one class on another class should be established on the smallest interface.
An interface represents a role, and different roles should not be handed over to an interface. The unrelated interfaces are merged together to form a bloated large interface, which is a pollution to the role and interface.
"Customers should not be forced to rely on methods they do not use. Interfaces belong to customers, not the class hierarchy they are in." This is very clear. In simple terms, don't force customers to use methods they do not use. If users are forced to use methods they do not use, then these customers will face changes caused by changes in these methods they do not use.
<?php interface A { public function getAge(); } interface B extends A { public function getName(); } class D implements A { /** * interface @Override */ public function getAge() { return 22; } } class C extends D implements B { /* * interface @Override */ public function getName() { return 'Brother Yong'; } } header("content-type:text/html;charset=utf-8"); $c = new \C(); echo $c->getName(); ?>
Running results:
Brother Yong
For more information about PHP related content, please check out the topic of this site:PHP object-oriented programming tutorial》、《Complete collection of PHP array (Array) operation techniques》、《Introduction to PHP basic syntax》、《Summary of PHP operations and operator usage》、《Summary of usage of php strings》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php》
I hope this article will be helpful to everyone's PHP programming.