1/7
SOLID Design Principles + A Couple Of Others
What is the ‘S’ in the SOLID Design Principles?
Single Responsibility - A class should only have a single functionality.
E.g The “Printing” class doesn’t contain functionality relating to document formatting.
What is the ‘O’ in the SOLID Design Principles?
Open/Closed - Classes are open for addition, closed for modification.
E.g Adding new functionality to a class doesn’t require you to touch the exisiting code in order to make it work.
What is the ‘L’ in the SOLID Design Principles?
Liskov Substitution - Any instance of a superclass can be replaced by it’s subclass without issue. (Prevents the inheritance of unnecessary features by subclasses)
E.g The Rectangle class could be substituted in an instance of the Square superclass with no error.
What is the ‘I’ in the SOLID Design Principles?
Interface Segregation - A class should rely on multiple specific interfaces rather than one general interface.
E.g Uses interfaces for “Intractable”, “Destroyable” and “Movable” objects rather than having one interface handle all of this functionality.
What is the ‘D’ in the SOLID Design Principles?
Dependency Inversion - A class should not rely on the implementation details of its dependancy.
E.g The restaurant class holds a “MenuFactory” class, it should not need to know the specific implementation details in order to depend upon MenuFactory.
What is Cohesion? Do we want High or Low Cohesion?
Cohesion is the degree to which elements of a module/class belong together. Generally we want high Cohesion.
What is Coupling? Do we want High or Low Coupling?
Coupling is the degree of independence between software modules. Generally we want low Coupling.
What is the Law Of Demeter?
The principle of least knowledge: Modules shouldn’t “reach through” modules to access information from classes that are not their immediate neighbours.
E.g restaurant.menu().appetizer().topping()