Liskov Substitution Principle
The Liskov Substitution Principle says that objects of the same interface should be interchange-
able without affecting the behavior of the client program
¹⁵
.
This principle sounds confusing at first, but is one of the easiest to understand. In PHP, interfaces
give us the ability to define the structure of a class, and then follow that with as many different
concrete implementations as we want. The LSP states that all of these concrete implementations
should be interchangeable without affecting the behavior of the program.
So if we had an interface for greetings, with various implementations:
¹⁴
If you want to see a complete example of this concept in action, checkout
¹⁵
http://www.objectmentor.com/resources/articles/lsp.pdf
SOLID Design Principles
36
Do'stlaringiz bilan baham: |