The Single Responsibility Principle states that each module in a system should be responsible for a single feature or functionality, or aggregation of cohesive functionality. Another common way to put it is to say that each module should have only one reason to change.

learn more… | top users | synonyms (1)

1
vote
2answers
85 views

Databases and the single responsibility principle

Can the single responsibility principle be applied to databases? relational databases I mean. I'm asking this because a typical database will have several tables and we may find something like that ...
2
votes
1answer
183 views

Design Patterns for creating tasks

I am developing software where each action in my entities need create tasks that will be execute in my infrastructure. When I create a task it is only records in the database. Afterwards, a windows ...
1
vote
1answer
200 views

Confused about implementing Single Responsibility Principle

Please bear with me if the question looks not well structured. To put you in the context of my issue: I am building an application that invoices vehicles stay duration in a parking. In addition to ...
2
votes
2answers
76 views

MVC design pattern. Overloading controller responsibilities

I'm developing a desktop application with a GUI. To do so, I'm using the MVC design pattern for the GUI part. For now the application consists of a single window (view) with one controller ...
1
vote
2answers
208 views

How to refactor code that has 2 concerns

Say I have this code: if ($this->ship == "e") { $this->price->addLine($this->price->base * $this->price->e, 0, "Export"); ...
4
votes
4answers
390 views

MVC: Does the Controller break the Single Responsibility Principle?

The Single Responsibility Principle states that "a class should have one reason the change". In the MVC pattern, the Controller's job is to mediate between the View and the Model. It offers an ...
3
votes
1answer
188 views

OO design choice and single responsibility principle

I'm currently refactoring an application which periodically downloads content from various sources (http, ftp, sql, etc). There is a schedule which controls the times during which the application can ...
35
votes
11answers
4k views

Ensure that each class has only one responsibility, why?

According to Microsoft documentation, the Wikipedia SOLID principe article, or most IT architects we must ensure that each class has only one responsibility. I would like to know why, because if ...
0
votes
0answers
115 views

API Client Design

I'm designing a client to the Tomtom WEBFLEET.connect API in PHP. (You can read more about the API through the full documentation here: ...
9
votes
2answers
314 views

Too many CS files in a single project [duplicate]

I am working on a ‘brown-field’ project, with a team of programmers. I understand each programmer will have different styles. I am running into some criticism with my coding style, specifically ...
2
votes
1answer
109 views

Single Responsibility Principle and higher levels of abstraction

Two common phrasings for the Single Responsibility Principle (SRP) are "each module should be responsible for a single feature or functionality in a system", and "each module should have only one ...
1
vote
5answers
419 views

Lots of classes with only one single static method with same name as class - Code smell? [duplicate]

I'm trying to follow the single responsibility principle (SRP) in my applications. I have lots of CRUD classes I just name xxxxxManager. Following the SRP, I made 4 classes for each one : ...
14
votes
7answers
1k views

Should I refactor large functions that mostly consist of one regex? [closed]

I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, ...
0
votes
1answer
114 views

Should a class validate argument using external method/service with unit testing?

I have a class that runs as a service and returns html code of a website when supplied with a URL. The code: public interface IHtmlDownloader { IWebProxy Proxy { get; set; } string UserAgent ...
0
votes
3answers
164 views

Doesn’t active record violate SRP and OCP?

I have watched the active record classes in our project grow into large, do-it-all classes. When you need anything about a user, for example, you should go to the Person class. While this makes ...
0
votes
0answers
48 views

MVVM / API design: who is responsible for what in the example inside?

Note: this question is about the MVVM pattern in general and not related to any specific MVVM framework. I am wondering what the best design approach for the requirements below is (hypothetical ...
2
votes
2answers
180 views

Achieving multiple tasks within one loop

With relation to what's considered good OOP engineering principles, SOLID, DRY, KISS etc I am wondering whether to complete multiple tasks within one loop when easily done. The problem is that this ...
5
votes
2answers
300 views

Constructor Injection, Single Responsibility and List initialisation

Given the class: public class Foo : IFoo { private IBarRepository repository public Foo(IBarRepository repository) { this.repository = repository } public IList<IBar> Bars { ...
2
votes
2answers
236 views

Single responsibility vs procedural programming

Single responsibility (from SOLID) is like making me create classes with only one public method. But if it's so, it would be possible use static methods, and go back to procedural programming. What's ...
3
votes
3answers
211 views

How is DRY principle ( applied at class level ) related to SRP?

In other words, is DRY (don't repeat yourself) applied at a class level a subset of SRP (single responsibilty principle)? What I mean is that while SRP states that each class should have only a ...
4
votes
3answers
106 views

Separate the renderer from the business model

I have a small responsibility separation issue that I hope someone can clarify. I have a small model composed by 2 classes: GameBoard and GamePiece, and the obvious relationship is that a GameBoard ...
22
votes
8answers
2k views

What is the real responsibility of a class?

I keep wondering if it is legitimate to use verbs that are based on nouns in OOP. I came across this brilliant article, though I still disagree with the point it makes. To explain the problem a bit ...
11
votes
5answers
483 views

Code repetition vs multi responsible method

I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of ...
0
votes
0answers
49 views

Abstracting complexity of transactional key value store

Our application stores settings in the platform's "transactional key-value store". prefs.edit().putInt("a", 1).commit(); int a = prefs.getInt("a"); I'd like to refactor our code for the following ...
1
vote
1answer
100 views

Discovering functionality from parallel class hierarchy

I have an abstract syntax tree which I want to compile down to different representations. I am now struggling to arrange the classes in a way that new representations can be added easily. The easiest ...
2
votes
1answer
194 views

Designing and refactoring of payment logic [closed]

Im currently working on an application that helps users to coordinate dinner clubs and all related accounting. (A dinner club is where people in a group, take turns to cook for the rest and then you ...
3
votes
1answer
645 views

Standard practices for access control (design pattern)

I'm looking at my interface design and I am struggling to decide which is the most "correct" way to implement role-based access control, given a user and a subject that the user would like to access. ...
5
votes
2answers
268 views

Does increasing the number of classes increase code complexity? [duplicate]

To illustrate the question, let's say we have two programmers of comparable skill that both solve the same problem. The code they turn out has roughly the same lines of code, but one programmer uses 5 ...
0
votes
2answers
104 views

should I create a new class for a specific piece of business logic?

I have a Request class based on the same Entity in my Domain. It currently only has property definitions. I'd like to add a method for checking a duplicate Request which I'll call from my ...
3
votes
5answers
288 views

Avoiding the Anaemic Domain - How to decide what single responsibility a class has

Even after reading a bunch I'm still falling into the same trap. I have a class, usually an enity. I need to implement more than one, similar operations on this type. It feels wrong to (seemingly ...
5
votes
3answers
451 views

OO - are large classes acceptable? [duplicate]

Despite many years in IT, I still struggle with OO design. One particular problem I seem to keep ending up with is large classes, often containing many hundreds of lines of code. The OO world talks a ...
2
votes
2answers
458 views

Is it a Single Responsibility Principle violation?

I'm designing an OO graph library and at the moment I'm trying to figure out the design for a GraphEdge class. I've added setters and getters for it's nodes, direction and weight. This seemes ...
6
votes
2answers
430 views

Is it good to have an interface plenty of methods which belong to different concepts, just to preserve the Liskov's Principle?

I'm currently studying a course based on Software Design and I had a discussion in class with my professor and some classmates about a problem represented by the next scenario: Scenario Imagine ...
7
votes
3answers
674 views

Is Domain Entity violating Single Responsibility Principle?

Single responsibility ( reason to change ) of an entity should be to uniquely identify itself, in other words, its responsibility is to be findable. Eric Evan's DDD book, pg. 93: most basic ...
3
votes
4answers
506 views

Are Compiler Directives an Antipattern?

I'm working on a legacy system that has a helper class that is symbolically linked into many different .Net projects within a solution. The logic is riddled with compiler directives that change it's ...
18
votes
10answers
2k views

Can/should the Single Responsibility Principle be applied to new code?

The principle is defined as modules having one reason to change. My question is, surely these reasons to change are not known until the code actually starts to change?? Pretty much every piece of code ...
4
votes
3answers
538 views

Do setters and getters always break the Single-Responsibility Principle?

As we know, The SRP states that every class should have single responsibility and that responsibility must be entirely encapsulated by the class. But setters and getters do serve another ...
5
votes
3answers
188 views

How do I design a DAL when I have to deal with relationships?

Say I'm developing a bug tracker, where a ticket belongs to at most one milestone, and a milestone can have many tickets. When a milestone is deleted (from the database), all tickets associated with ...
0
votes
1answer
134 views

Design patterns to avoiding breaking the SRP while performing heavy data logging

A class that performs both computations and data logging seems to have at least two responsibilities. Given a system for which the specifications require heavy data logging, what kind of design ...
2
votes
2answers
302 views

Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member

Architecturally speaking, which is the preferable approach (and why)? $validation_date = $users_repository->getUser($user_id)->validation_date; Seems to violate Law of Demeter by accessing ...
32
votes
6answers
2k views

How do I prove or disprove “god” objects are wrong?

Problem Summary: Long story short, I inherited a code base and a development team I am not allowed to replace and the use of God Objects is a big issue. Going forward, I want to have us re-factor ...
3
votes
2answers
333 views

Questions about identifying the components in MVC

I'm currently developing an client-server application in node.js, Express, mustache and MySQL. However, I believe this question should be mostly language and framework agnostic. This is the first ...
0
votes
1answer
1k views

Low Coupling: Single Responsibility Principle vs Cohesion

I've read several articles on SRP and cohesion, and they seem to contradict each other as far as low coupling is concerned. Articles on cohesion argue that putting closely related responsibilities ...
9
votes
2answers
435 views

Is there an “ask for only what you need” interface principle?

I have grown into using a principle for designing and consuming interfaces that says basically, "ask for only what you need." For instance, if I have a bunch of types that can be deleted, I'll make ...
15
votes
6answers
1k views

Does multiple inheritance violate Single Responsibility Principle?

If you have a class which inherits from two distinct classes, does not this mean that your subclass automatically does (at least) 2 things, one from each superclass? I believe there is no difference ...
8
votes
6answers
836 views

What are the practical ways to implement the SRP?

Simply what are the practical techniques people use to check if a class violates the single responsibility principle? I know that a class should have only one reason to change, but that sentence is ...
3
votes
2answers
463 views

How do you follow the single responsibility principle in classes responsible for behaviour?

I have many classes in my application responsible for behaviour- views, controllers, models, network- often the state of one class or system depends on another and I'm finding that classes that are ...
-2
votes
1answer
248 views

Single Responsibility Principle: Responsibility unknown [closed]

I store sessions in a SessionManager. The session manager has a dependency to ISessionPersister. SessionManager private readonly ISessionPersister sessionPersister; public ...
8
votes
3answers
1k views

What is the difference between Single Responsibility Principle and Separation of Concerns

a)What is the difference between SRP and SoC? Perhaps that SRP is applied at class level, while SoC can be applied at system, subsystem, module, class or function levels. b) If answer to a) is yes, ...
2
votes
1answer
183 views

Something confusing about Single Responsibility Principle

1) In fact if two responsibilities are always expected to change at the same time you arguably should not separate them into different classes as this would lead, to quote Martin, to a "smell ...