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)

2
votes
1answer
84 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
197 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
105 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 ...
2
votes
1answer
46 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
93 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
238 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
110 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
648 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
127 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
54 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
74 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
176 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
106 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
69 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
400 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
98 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
313 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
13 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
398 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
307 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
150 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
272 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
231 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
147 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
233 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
208 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
347 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
139 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
653 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
230 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
261 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
212 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
316 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 { ...
4
votes
2answers
290 views

Single responsibility vs procedural programming [duplicate]

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
435 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
130 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 ...
25
votes
8answers
3k 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
538 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 ...
1
vote
1answer
133 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
207 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 ...
5
votes
1answer
1k 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
322 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
107 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 ...
4
votes
5answers
365 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
618 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
607 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 ...