Posts

Showing posts from May, 2017

S.O.L.I.D principles

Image
The S.O.L.I.D principles of Object Oriented Design( OOD ) include these five principles. Lets expanded the acronyms: S  - Single-responsibility principle O  - Open-closed principle L  - Liskov substitution principle I  - Interface segregation principle D  - Dependency inversion principle # Single-responsibility  principle ( S.R.P ) A class should have only one job. O ne and only one reason to change. Examples of responsibilities : Persistence Validation Notification Error Handling Logging Formatting Parsing Mapping # Open-closed principle ( O.C.P ) A class should be open for extension, but closed for modification. # Liskov substitution principle ( L.S.P ) Subtypes must be substitutable for their base types.   In mathematics, a  Square  is a  Rectangle . Indeed it is a specialization of a rectangle. The "is a" makes you want to model this with inheritance. However if in code you made  Square  derive from  Rectangle , then a  Square  sh