Good Production Code Flashcards
What does SOLID stand for?
- Single Responsability
- Open Closed
- Liskov’s Substitution
- Interface
- Segregation
- Dependency Inversion
What is the Single Responsibility Principle?
There should NEVER be more than ONE reason for a class to change → ONE JOB
What are (3) indicators for the Single Responsibility Principle?
- Many public functions
- Unrelated functions
- Various class clients
What is a class client?
A class using another class’s public funtions
How to follow the Single Responsibility Principle?
Division into multiple simple classes with…
- composition
- aggregation
- dependency
What is the Open Closed Principle?
Classes should be open for extension but closed for modification.
→ Never modify a class in order to handle a new one
What are (2) indicators for the Open Closed Principle?
- Modification needed to handle a new class
3. Switch-Case to check object type
How to follow the Open Closed Principle?
- (Abstract classes)
2. Interfaces
When is it okay to use switch-case?
In a Factory Pattern to ask “Who do you wanna be?”
Explain the Dependency Inversion Principle
Never depend on (call) a concrete class! Always depend on your own abstractions.
What are (2) indicators for the Dependency Inversion Principle?
- Dependency on concrete classes
2. Long chain of dependencies (coupling)
How to follow the Dependency Inversion Princliple?
- Dependency upon high level abstractions with low level implementation
- Interfaces as Boundaries between layers
What patterns use the Dependency Inversion Principle?
- Adapter
- Template
- Strategy
Explain the adapter pattern
Integration (use) of any class without your own Interface and without modifying the target class
Explain the template pattern
Seperation of algorithm and its implementations with inheritance