Created
October 4, 2019 19:35
-
-
Save najmubadr/c9be6a3a9f68c4b7a951eccca1385c2c to your computer and use it in GitHub Desktop.
PHP solid принцип разделения интерфейса Interface segregation principle, ISP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ITransformer.php | |
| <?php | |
| /** | |
| * Solid | |
| * I - принцип разделения интерфейса | |
| * Interface segregation principle, ISP | |
| * Клиенты не должны зависеть от методов, которые они не используют | |
| * | |
| * Много специализированных интерфейсов лучше, чем один универсальный | |
| */ | |
| interface ICarTransformer { | |
| public function toCar(); | |
| } | |
| interface IPlaneTransformer { | |
| public function toPlane(); | |
| } | |
| interface IShipTransformer { | |
| public function toShip(); | |
| } | |
| // transformers.php | |
| <?php | |
| class SuperTransformer implements ICarTransformer, IPlaneTransformer, IShipTransformer { | |
| public function toCar() { | |
| echo 'transform to car'; | |
| } | |
| public function toPlane() { | |
| echo 'transform to plane'; | |
| } | |
| public function toShip() { | |
| echo 'transform to ship'; | |
| } | |
| } | |
| class CarTransformer implements ICarTransformer { | |
| public function toCar() { | |
| echo 'transform to car'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment