Below principles are extracted from the excellent PHP book: PHP In Action.
1. THE OPEN-CLOSED PRINCIPLE
A class should be open to extend, closed to modification. A refactoring technique is also regarded in this principle: Replace conditional with polymorphism.
In real world: when a new requirement comes up, what a programmer usually do is, open the source code, find the related part, put if (condition) {//do the new requirement}
2. THE SINGLE-RESPONSIBILITY PRINCIPLE
a class that tries to do everything will have to change frequently because
some responsibility it has needs to be updated. A class should have only one reason to change.
In real world: any other template engines except smarty can allow developers put business logic into it?
3. THE DEPENDENCY-INVERSION PRINCIPLE
GoF tell us: program to an interface, not an implementation.
4. LAYERED DESIGNS
No comments:
Post a Comment