
上QQ阅读APP看书,第一时间看更新
Other common design principles
Other common principles are as follows; however, detailing of each principle is not in the scope of this chapter, and we request you to refer to other materials if you need to read more information about those principles:
- Encapsulate
- Always encapsulate the code that you think may change sooner or later
- Composition over inheritance
- In some cases, you may need the class behavior to change during runtime, and those cases favor composition over inheritance
- Program for interface (not for the implementation)
- Bring flexibility to the code and can work with any new implementation
- General responsibility assignment software patterns (GRASP)
- Guides in assigning responsibilities to collaborate objects
- Don't repeat yourself (DRY)
- Avoid duplicate codes by proper abstraction of the common codes into one place
- Single layer abstraction principle (SLAP)
- Every line in a method should be on the same level of abstraction