Object Oriented Design Principles: SOLID, …
Table of Contents
1 Data Encapsulation v Abstraction v OOD
1.1 Encapsulation
- A "data structure" is declared.
- Certain operations are declared to be "public".
- The "data structure" is accessed/manipulated only via the above.
1.2 Abstraction
- A "data type" is declared
- Certain operations are available
- The "data type" is an abstraction
- Concrete representation to Abstraction mapping
- E.g., an array of items ==> set of items
- Information Hiding Principle
- See ../Abstraction
1.3 Class Invariants
- Class invariants are assertions.
- Must be true before and after every public methods.
- Must be true after every constructor.
1.4 C++/Java/… Classes
- Provide data encapsulation
- Do not do Data Abstraction
- Language Design
- public v protected v private
- interface v class
2 Principles of Class Design (aka SOLID)
- (SRP) The Single Responsibility Principle
- (OCP) The Open Closed Principle: Classes and methods should be open for extension (of functionality) and closed for modification.
- (LSP) The Liskov Substitution Principle: Subtypes must be substitutable for super type. A sub class must enhance functionality, but not reduce.
- (ISP) The Interface Segregation Principle
- (DIP) The Dependency Inversion Principle
3 Principles of Package Cohesion
- (REP) The Reuse Release Equivalence Principle
- (CCP) The Common Closure Principle
- (CRP) The Common Reuse Principle
4 Principles of Package Coupling
- (ADP) The Acyclic Dependencies Principle
- (SDP) The Stable Dependencies Principle
- (SAP) The Stable Abstractions Principle
5 Design By Contract (DoC)
6 Liskov Substitution Principle (LSP)
7 References
- Web site, http://www.oodesign.com Recommended Visit
- Bob Tarr, UMBC.edu, Some OOD Principles PDF Slides. Recommended Reading
- Robert Bruce Findler, Mario Latendresse, and Matthias Felleisen. Behavioral Contracts and Behavioral Subtyping. In Proceedings of ESEC/FSE-9, 229-236. http://www.ccs.neu.edu/scheme/pubs/fse01-flf.pdf 2001 Recommended Reading.
- Bertrand Meyer. Applying "Design by Contract". IEEE Computer, 25(10):40–51, October 1992. http://se.ethz.ch/~meyer/publications/computer/contract.pdf Also in his book "Object-Oriented Software Construction". Required Reading.