Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [single-responsibility]

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.

-3
votes
0answers
58 views

OOP C#, Java, How should many classes and objects communicate to accomplish a task? [on hold]

If we are following the single responsibility principle then a big program should have hundreds or thousands of classes, however I've yet to find an explanation on how exactly these 100-1000s of ...
3
votes
2answers
202 views

Does method argument self-sanity checking violate the SRP?

I have a method login() which essentially sends a login request to a remote server. As I do not want to waste server resources on processing invalid data, I decided to consider sanity checking the ...
2
votes
2answers
179 views

Single responsibility principle - importer

I'm writing an importer, it should fetch some data from the database and put that data into appropriate places. Now the question is, should the importer itself fetch that data, or should that data(to ...
0
votes
2answers
85 views

Apply Single Responsibility Refactoring in Form App

I really don't understand the SRP applied to a "real" project (really not so real but can help me to know your approach) I find very difficult to divide and assign responsibility to my classes. So I ...
7
votes
7answers
744 views

Separation of concerns: When is it “too much” separation?

I really love clean code and I always want to code my code in the best possible way. But there was always one thing, I didn't really understand: When is it too much of "separation of concerns" ...
1
vote
1answer
253 views

Entity Framework - extending OR injecting services into DB Context

I fear I'm asking a somewhat silly question, but I'm now completely lost as to which principle I should follow. To my understanding - in terms of Single Responsibility Principle it's best we don't ...
2
votes
3answers
417 views

Designing a REST API with resource relationships?

I'm working to design a REST API to be consumed by a React SPA. The client-side of the SPA queries data about a relationship between two entities: Team and Player where Teams have many Players and ...
2
votes
3answers
169 views

Does SRP feed tight coupling?

I designed a function which, afterwards, I noticed it is clearly doing 2 very different tasks in the same time. So now I am thinking to split it into 2 different functions, each one of them doing ...
2
votes
1answer
66 views

Refactoring of a client calling a Rest Service

I have a class that is responsible for calling a service and returning a response. The contract is like this interface ServiceClient { ServiceResponse process(ServiceSubmissionParams params); } ...
4
votes
2answers
224 views

Is it violation of single responsibilty to add a method to an existing API

Say i have a Rest API that has a POST and GET method. If i want to overwrite a resource in the API i can call the GET method to get the original item and then call the POST method to replace that ...
3
votes
4answers
421 views

Is Abstracting your code too much a bad use of SOLID Principles?

After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come ...
-1
votes
2answers
91 views

How to choose the most suitable solution for a problem given some choices?

To ilustrate my main concern let's start by considering a "trivial" typical problem, data filtering & parsing coming from a process and dumping the information onto something {gui console, file, ...
7
votes
6answers
1k views

How to know when to use dependency injection?

The question might sound a little weird, and I guess it is. I'm came up with the question while browsing through some design patterns. I came to the notorious state / strategy pattern and I came up ...
0
votes
0answers
92 views

Better pattern to ensure single responsibility

What's a better pattern here to ensure that my methods follow the single responsibility principle. I have a pretty DRY controller, that I think makes sense and is concise. Here is my controller: ...
1
vote
5answers
234 views

Single Responsability actor or use case?

I've been struggling to grasp my head around the SRP pattern, because I dont know if it refers to a actor o to the use case. In the following case: To don't violate the SRP, would you need to create ...
0
votes
2answers
173 views

OOP, SRP, and Checkers

I have just started oop and decided to program a checker's engine. I have few concerns about the way that I have structured my code and I am not sure if I am failing to understand the principals ...
0
votes
3answers
115 views

Separated implementations or one with all functionalities

I am currently creating Excel import modules for some complex data. I didn't plan it well and I have met code reuse issues. I have made first modules and I realized that next modules will need some ...
-5
votes
1answer
51 views

Naming abstract class for object creation and update views

How can I name an abstract class that has a common part of view of my two panels? One of them is for creating an object and the other one is for updating it. I want to keep these view in different ...
2
votes
2answers
128 views

Is replacing the call to mutual exclusive methods by an injected strategy overengineering?

I recently gave advice to refactor some code along the lines of class Validator<T> : IValidator { public ValidationResult Validate(Validatable thingToValidate) { if(typeof(T)....
0
votes
0answers
87 views

Send records to messaging queue using either of one policy

I have bunch of keys (clientKey) and values (processBytes) that I want to send to our messaging queue by packing them in one byte array. I will make one byte array of all the keys and values which ...
0
votes
1answer
40 views

Object Responsibility and Calculations

Trying to work out where certain responsibilities lie with the following example. We have a Project object and a Project can have Time entries booked against it. Each Time entry will have a no. of ...
0
votes
0answers
60 views

Understanding Single Responsibility Pattern (SRP) [duplicate]

According to the Single Responsibility Pattern (SRP) a method or class should have one responsibility. I have read a couple of sources and viewed some videos and I would like to understand it by ...
1
vote
0answers
116 views

How to decouple a message broker and its message handlers?

Project description: I have a nodejs project where I try to build a bluetooth mesh like network, each node consists roughly of 4 parts the frontend part, the message broker, a bluetooth client and a ...
3
votes
2answers
103 views

Collection calculating too much?

Let say I've abstracted away a data structure such as a list; should this new object perform all the calculations or just provide minimal calculation functions and then allow a new object such as ...
12
votes
5answers
632 views

Is it useful to mini-refactor code in hopes of improving quality, or is it just “moving code around” without much of a benefit?

Example I came across monolithic code that does "everything" in one place - loading data from database, showing HTML markup, acting as a router/controller/action. I began applying SRP moving ...
0
votes
2answers
182 views

Where should I put the database access method in a treeview environment

I have written a class to represent 'Treeview-like' data, which can be simplified as: public class Item { public string Name { get; set; } public KPI AssociatedKPI { get; set; } public ...
4
votes
4answers
451 views

Is SRP an ambiguous principle? [closed]

I've been aware of SOLID for many years now and I've always though about "OLID" was a good set of design principles to follow... problem is I've always found difficulties with the "S", I've always ...
4
votes
4answers
431 views

Please explain why we need SRP in “Plain English” despite its drawbacks?

Can you in "plain English" explain why we need Single Responsibility Principle? Especially that it moves the what I call "bloat" into other places. See below for more info. By bloat I mean in my ...
9
votes
7answers
767 views

Am I making my classes too granular? How should Single Responsibility Principle be applied?

I write lots of code that involves three basic steps. Get data from somewhere. Transform that data. Put that data somewhere. I typically end up using three types of classes - inspired by their ...
3
votes
4answers
561 views

Single responsibility of a function

I would like to find out if I understand single responsibility principle correctly. The function below is suppose to return user ID store in database by using the SAM account name pass into it. Look ...
0
votes
1answer
109 views

ItemManager class has too many responsibilities (load items, give items, has a reference to ItemsList)

So my manager class does 2 things, load items from file and give one item to a thread that asks for it, it also holds the List that will contain all the items. using System; using System.Collections....
0
votes
1answer
460 views

Should I separate into own class when creating private methods in service layer?

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer. I have a Web Api 2.0 Controller called ...
66
votes
12answers
13k views

Does a constructor that validates its arguments violate SRP?

I am trying to adhere to the Single Responsibility Principle (SRP) as much as possible and got used to a certain pattern (for the SRP on methods) heavily relying on delegates. I'd like to know if this ...
3
votes
3answers
152 views

SRP processing file line-by-line

I'm writing a class that read lines from a file, process them, store them in an accumulator and when it reaches a threshold bulk inserts in a SqlServer database. Like this: class ...
1
vote
1answer
134 views

Encapsulation and SRP

Suppose I have the following requirements: We organize books by author first name, this might change in the future. When ever an Author we carry at our store releases a new book, the Authors previous ...
3
votes
1answer
610 views

Domain Objects and How they Access the Database

Suppose I have the following class: public class Course { // data public string Name { get; } public List<Student> Students {get;} //... // logic public int ...
0
votes
2answers
139 views

Does Template pattern violate Single Responsibility principle?

Assume we have the following class: class Foo { public: void func() { _func1(); _func2(); } private: virtual void _func1(); virtual void _func2(); }; This class, from one ...
0
votes
1answer
60 views

Api and Auth tightly coupled circular dependancy

I am programming an application and am having trouble finding a good architecture for some of its components. As part of the front-end app, I have a user authentication system and an API that allows ...
4
votes
3answers
403 views

How to apply the single responsibility principle if the program should do a lot of things?

If I need to write a program that Reads a json file Converts its data to yaml Writes it to yaml file and adhering to the single responsibility principle I create classes like FileReader ...
2
votes
1answer
194 views

react-redux (React bindings) vs Virtual Dom and Single responsibility principle

I understand React and Redux (at least think that I do). But the combination using the react-redux Binding package is a bit confusing to me. https://github.com/reactjs/react-redux The first thing ...
0
votes
1answer
80 views

Does putting AddCustomerData, GetAllCustomers and GetCustomerByID in one class violate SRP?

I am little bit confused about whether I can put all below functions to one class or if I should split into more classes. I think GetCustomerByID and AddCustomerData got different responsibilites but ...
4
votes
1answer
290 views

Dealing with a large interface

I'm working on a program that solves a certain type of systems of equations. The main data objects are Equation, Variable, Solution. Then I have this interface, which represents all things that I want ...
2
votes
6answers
493 views

How to apply SRP in a loop where two things need to be done?

Is there a way to apply the Single Responsibility Principle to a function where two things need to occur in a loop in order to not need to iterate twice? For example, suppose I have a function like ...
-2
votes
2answers
199 views

Change in constructor parameter or ways to decompose the constructor? [duplicate]

Class Book { private int year; private String session; private int volume; private int number; private String khand; private Date proceeding_date; private int pageNo; Book(year,session,...
1
vote
5answers
224 views

Dedicated method vs method with parameter

Suppose we've a permissionManager which tell us if user has some privileges to some action or not. We've quite a lot of them(dozen, maybe more). I see two ways to implement checks for a user, like a: ...
0
votes
1answer
45 views

Debug class responsibility, accessability

So I'm writing a Flocking System (http://www.red3d.com/cwr/boids/). Each boid calculates it's vectors, I would like to draw these vectors with a helper class for debugging purposes. Who should ...
1
vote
1answer
114 views

Do iOS view controllers and their viewDidLoad method violate the single responsibility priniciple?

I am learning about OOP principles and realized that on iOS view controllers become massive because we tend to stuff all the view responder methods in them. A lot of stuff happens in the viewDidLoad ...
0
votes
1answer
178 views

Does this Repository code violate SRP and DRY?

After reading this Stackoverflow question I have stumbled upon an MSDN article Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application. There is a proposed implementation ...
2
votes
5answers
228 views

Using SRP with Object Thinking

According to David West, Object Thinking involves identifying Objects in the problem/business domain that mirror real-world objects; the interface would then reflect the behaviors of that object. ...
8
votes
8answers
830 views

Single Responsibility Principle Violation?

I recently got into a debate with another developer regarding the below class: public class GroupBillingPayment { public void Save(IGroupBillingPayment model) { if (model == null || ...