Skip to main content

SOLID - Single Responsibility - Principle



In real world SDLC, there will be times where we might need to change our code due to the various reasons and requirement changes. The Single Responsibility Principle (SRP) will drive developers to write code so that a class with single responsibility will only has one and only one reason to change. If a developer find out that during his changes, there is more than one changes to be made, it means it has more than one responsibility and might break other dependencies to the class. Classes with more than a one responsibility should be broken down into different classes, each of which should have only one responsibility and reason to change.

Before we dive deeper lets take a look and an example of a class that have too many responsibilities.



We will dive into some example in c# and make use the process of delegation and abstraction. A class with too many responsibility should be delegated to one or more classes. By using the bad example above we will discuss on how to use below techniques to fulfill the Single Responsibility Principle.

1. Refactor Using Delegation
2. Refactor Using Abstraction


Published on : 10-Jan-2019
Ref no : DTC-WPUB-000096

About Author

My photo
Wan Mohd Adzha CAPM,MCPD,MCSD,MCSE
Passionate about new technology ( Software Engineering ) and how to build,manage and maintain them

Comments