How do you define a Single Responsibility?

The Single Responsibility Principle There are many obvious cases, e.g. CoffeeAndSoupFactory. Coffee and soup in the same appliance can lead to quite distasteful results. In this example, the appliance might be broken into a HotWaterGenerator and some kind of Stirrer. Then a new CoffeeFactory and SoupFactory can be built from those components and any accidental …

Read more

What is an example of the Single Responsibility Principle? [closed]

The most effective way to break applications is to create GOD classes. Those are classes that keep track of a lot of information and have several responsibilities. One code change will most likely affect other parts of the class and therefore indirectly all other classes that use it. That in turn leads to an even …

Read more

Learning Single Responsibility Principle with C#

Let’s start with what does Single Responsibility Principle (SRP) actually mean: A class should have only one reason to change. This effectively means every object (class) should have a single responsibility, if a class has more than one responsibility these responsibilities become coupled and cannot be executed independently, i.e. changes in one can affect or …

Read more

Single Responsibility Principle vs Anemic Domain Model anti-pattern

Rich Domain Model (RDM) and Single Responsibility Principle (SRP) are not necessarily at odds. RDM is more at odds with a very specialised subclassof SRP – the model advocating “data beans + all business logic in controller classes” (DBABLICC). If you read Martin’s SRP chapter, you’ll see his modem example is entirely in the domain …

Read more

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

SRP tells us that you should only have a single responsibility in a module. ISP tells us that you should not be forced to be confronted with more than you actually need. If you want to use a print() method from interface I, you shouldn’t have to instantiate a SwimmingPool or a DriveThru class for …

Read more

Difference between Single Responsibility Principle and Separation of Concerns

Single Responsibility Principle (SRP)- give each class just one reason to change; and “Reason to change” == “responsibility”. In example: Invoice class does not have a responsibility to print itself. Separation of Concerns (since 1974). Concern == feature of system. Taking care of each of the concerns: for each one concern, other concerns are irrelevant. …

Read more