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.
1
vote
0answers
41 views
Apply Single Responsibility Principle on a Button
I'm on Android and I have a class that represent a button on the screen. This class has two methods, one for click event and other for long-click event. Boths events do differents things.
So, ...
0
votes
0answers
11 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
347 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
290 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
100 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
205 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
215 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
101 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
214 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");
...
5
votes
4answers
561 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
195 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
140 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
323 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
114 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
514 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
144 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
178 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
54 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
188 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
308 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
252 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
261 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
113 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 ...
23
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
492 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
50 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
110 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
199 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 ...
4
votes
1answer
829 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
282 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
105 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
304 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
528 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
510 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
450 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
771 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
515 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
564 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
191 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
142 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
340 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 ...
33
votes
6answers
3k 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
350 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
460 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
898 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 ...