2. Single Responsibility Principle (SRP) Flashcards
What are the SOLID principles comprised of?
Five individual principles for writing better software, especially in object-oriented languages.
What does the SRP state?
Each software module should have one and only one reason to change.
What is a module in the context of a C# program?
A module in C# might refer to a class or even a single function.
How can we improve the design of our software when it comes to the proximity between what the application does and how it does it, and how?
By separating the “what” from the “how”. We do this through delegation and encapsulation.
How can we improve the design of our software when it comes to the proximity between what the application does and how it does it, and how?
By separating the “what” from the “how”. We do this through delegation and encapsulation.
What should the classes encapsulate?
ps. Encapsulation in the general sense.
Doing a particular task in a particular way.
What can be said about single-purpose classes?
They do a single particular task in a particular way, and they are easy to use.
What can be said about the performance of multipurpose tools vs dedicated tools?
Multipurpose tools don’t perform as well as dedicated tools.
What can be said about the performance of multipurpose tools vs dedicated tools?
Multipurpose tools don’t perform as well as dedicated tools.
What is a responsibility in the context of the SRP?
It’s the answer to the question of how something is done.
It’s a decision our code is making about the specific implementation details of some part of what the application does.
What are some examples of responsibilities?
- Persistence
- Logging
- Validation
- Business Logic
What do responsibilities in our code represent in regards to change and the SRP?
Responsibilities represent things that may change at different times and for different reasons — each responsibility is a different axis of change.
What happens when two or more details are intermixed in the same class?
It introduces tight coupling between these details.
What is tight coupling?
Binding two or more details together in a way that’s difficult to change.
What’s the difficulty that tight coupling brings?
If the tightly coupled details change at different times for different reasons, it’s likely to cause problems in the future with code churn in the class in question.