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
3answers
124 views

How to understand if a property is a member of a class or I have to create a different class that holds it?

Sometimes when you create a class you can add there several properties (new data members) that you are not certain if you want to do or not. For example, I have a casino slots game. I have tiles and ...
2
votes
1answer
53 views

SRP and Getters/Encapsulation

I recently watched this presentation of Robert C. Martin about the Single Responsibility Principle: https://www.youtube.com/watch?v=Gt0M_OHKhQE He presents an Employee class with multiple ...
0
votes
2answers
67 views

How to better define SRP and “wholesome” objects? [duplicate]

Assume you have a class. It can really be any class that defines a domain concept like an employee, a product on an e-commerce site, or a car. One of those examples that are oldies but goodies. ...
2
votes
2answers
128 views

How to avoid god controller classes and keep single responsibility principle?

The task is to make a migrator from Old DB to New DB using OOP Single Responsibility Principle. My problem is how can I make this without making the controller a God Class or breaking the single ...
2
votes
2answers
177 views

Why is modularity a good idea? [closed]

I have a programmer on my team who wants to take all the control flow logic for handling events sent by any module and put it all in a single file, because they think it will make an already-complex ...
0
votes
0answers
18 views

SRP in MVVM's ViewModel

I have a question about Single Responsibility Principle in MVVM. I'd like to create a group of views for Warehouse Mgmt. Software. They would be connected to properties from my document which should ...
3
votes
1answer
50 views

Can I resolve an issue with SRP, SOC that prevents object initialization via constructor?

In OOP, I can populate (initialize) an object using constructor injection at object creation time, or setter injection, after creation time. I like the idea of populating object at creation time via ...
2
votes
1answer
57 views

Why is SRP using the class construct to contain a responsibility opposed to using any other OOP entity?

SRP states ... There should never be more than one reason for a class to change. But why a class? Why not use granularity of a function/method? What instead of separating my functionality into ...
2
votes
2answers
139 views

Does it break SRP to have concerns of data handling and object mapping inside a single class, as part of the DataMapper pattern?

Summary I want to look into separating the concern of "creating a populated object from database", to use inside my application. DataMapper pattern seems to be doing just that for me. DataMapper ...
0
votes
3answers
109 views

How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?

I'm refactoring an old app to use dependency injection.n I'm pretty new to DI. I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to ...
4
votes
1answer
125 views

Where to initialize objects

I have an BallEntity class that is part of a game that uses a Entity Component System architecture. This class have 'components' that are like the attributes of that class. I create and initialize ...
1
vote
2answers
53 views

Responsibility of an ESB

When using an enterprise service bus, is it responsible for; a. the successful delivery of a message to a consuming application b. to successfully deliver a message until the application's ...
1
vote
2answers
435 views

Class becoming God Object what pattern to use

I am developing Android app and my MainActivity is becoming God Object. By the way native Activity class implementation is some sort of God Object already. The problem is that my activity class is ...
2
votes
2answers
159 views

Difference between Single Source Of Truth and Single Responsibility Principle?

So I just found out about the term single source of truth while watching video series about programming code interviews. From what I understood it meant that the single source of truth is an ...
2
votes
1answer
89 views

Pick dynamically the right Factory Class with Inversion of Control

I have a TreeView and I want to enable the context menu when clicking with the right mouse button. It is composed by items from different classes, but they all share the same base class. So, I was ...
2
votes
4answers
211 views

When should I mix functions with data in a class?

Based on some questions I asked (1, 2,3), I am frequently suggested to separate data from functions (because of changes in function, single responsibility, separation of concerns, adopting interfaces, ...
3
votes
1answer
130 views

Is the target of 3 dependencies per class always achievable?

I'm reading the Clean Code book and a chapter says that if a class has more than 3 dependencies is a code smell of that class isn't doing one thing. Or what is the same, it isn't following SRP. I'm ...
3
votes
1answer
73 views

Peculiar architecture interfacing .NET to AutoCAD out-of-process

I have written a set of classes to interact with AutoCAD from an out-of-process .NET assembly, but it seems like my class architecture and interactions are unusual. I am struggling to find a better ...
1
vote
2answers
120 views

Rich Domain Models, Encapsulation, and the Problem of Constructor Over-Injection

I am refactoring an e-commerce web-application, currently working on the UserBasket class, which will have to handle adding or removing items, changing their quantity, getting total amount, total ...
4
votes
2answers
260 views

What principle is violated by having a button do two radically different things or screens act radically different depending on the situation

I've come upon a situation several times in my career when previous developers have done something funny. They will make a control (button) function radically different depending on how the screen ...
14
votes
6answers
3k views

Is logging next to an implementation a SRP violation?

When thinking of agile software development and all the principles (SRP, OCP, ...) I ask myself how to treat logging. Is logging next to an implementation a SRP violation? I would say yes because ...
0
votes
2answers
116 views

Distinguishing Classes: How to catch system behavior in classes (Library System Case)

Suppose a Library System. if I think about Data, I can just distinguish Book, Member classes or at most Author or Publisher... (Are they only classes?), but I have some use cases, scenarios (Borrow, ...
7
votes
4answers
1k views

Is the Single Responsibility Principle applicable to functions?

According to Robert C. Martin, the SRP states that: There should never be more than one reason for a class to change. However, in his book Clean Code, chapter 3: Functions, he shows the ...
0
votes
2answers
136 views

Object oriented Classes and single responsibility [duplicate]

I'm reading a book that explain that it is a good thing that classes have a single responsibility, that is, that they do a single thing. I can understand how to implement this in some cases I ...
2
votes
0answers
72 views

Injecting data processing logic into class

I want find more elegant and appreciate way to inject processors into CommandProcessorDispatcher class. Or it can be another one solution (the goal is separate each command processing logic to ...
0
votes
1answer
85 views

Non-anemic model and SRP

I'm implementing a feature in legacy system right now. Instead of putting all my logic in some dummy application services and having anemic models, I thought I will try to do some OOP this time. I'm ...
5
votes
2answers
187 views

How to avoid “type dispatchers” when working with SOLID

I've realized that since I've been more and more strict about the SOLID principles, my code tends to consist of more pure data objects and a lot of "operator" classes which seems to go against ...
3
votes
2answers
128 views

Service Oriented Architecture - Component Responsibility

Working on an ecommerce project whereby a PHP application (back-end & non-customer facing) is currently responsible for processing an order from checkout stage through to generating profit/loss ...
1
vote
1answer
85 views

How to organize all classes derived from SRP?

As the SRP says, the way to achieve this principle is divide all into smaller. And what you have just made small, make more smaller. As consequence we got more files and my question is about it, how ...
3
votes
2answers
552 views

How do you apply Single Responsibility principle to a repository

I am trying to apply "SOLID" whenever I can and try to use common sense and avoid a pattern when I see that a pattern is creating more problems than it's trying to solve. I don't want to apply a ...
2
votes
0answers
101 views

Is this function violating Single Resp Principle?

public function obtenerColumna($delimitador='', $columna=0, $incluirRepetidos=false, $eliminarEspaciosAdyacentes=true, $filaDesde=0, $filaHasta=0) It obtains a column from a set of records ...
6
votes
3answers
355 views

Application of Single Responsibility Principle on a Button

I have a class that represents a button on the screen. This class has two methods: one for click event; the other for long-click event. Both events do different things. So, according to Single ...
0
votes
0answers
15 views

Deduplicating html-attached javascript on page

I have a paging "widget" that consists of HTML with attached javascript. The javascript is only needed once, but the widget could be on the page twice or more. For example, it could be at the top of ...
0
votes
5answers
421 views

Liskov Substitution and SRP Principle violation - how best to structure this scenario?

While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
0
votes
1answer
313 views

Single responsibility: how does this code cause problems?

Given the following interface interface Modem { public void Dial(string pno); public void Hangup(); public void Send(char c); public char Recv(); } Uncle Bob writes However, ...
1
vote
2answers
186 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
340 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
244 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
181 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
248 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"); ...
6
votes
4answers
1k 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
226 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 ...
9
votes
2answers
366 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
146 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
768 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 : ...
15
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
2answers
267 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
304 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 ...
2
votes
2answers
252 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 ...