COURS 1 : SOLID Flashcards
(6 cards)
What are the Patterns, Principles
and Best practices of solid?
- To deliver faster
- To manage change
- To manage complexity
What are the principles of Solid?
• A class needs to have a single responsibility • GRASP PRINCIPLE : High cohesion The methods of a class use a lot of the other members of the same class. • GRASP PRINCPLE :Low coupling :The methods of a class do not use many members from other classes. High cohesion + Low coupling → Less responsibilities, less reasons to change. • So, maintain the cohesion and the coupling of the class!
What do we mean when we say “Open-chest surgery isn’t needed when putting on a coat.”?
- The software entities need to be open to extensions, but close to modifications.
- Always think: “what will happen if the entity changes?”
Define the Liskov principle.
- The functions that use references to base classes must be able to use objects of the derived classes without knowing.
- The preconditions cannot be enforced in the derived type. The derived methods cannot expect more than the base methods.
- The postconditions cannot be more relaxed in the derived type. The derived methods cannot provide less than the base methods.
What is the interface segregation principle?
Multiple interfaces specific to clients are worth more than a single interface.
What is the dependency inverion principle?
• Depend on abstractions. Do not depend on concrete classes.
• The Holy Grail of software architecture!
• If we want to change the database, how many classes will we have to
change?
• If we depend on software libraries, our systems is locked within a
specific language (DIP violated).
• If we depend on REST APIs, our system remains independent of languages (DIP guaranteed).