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.

6
votes
6answers
503 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
69 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 ...
1
vote
3answers
114 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
153 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
61 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
219 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
398 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
85 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
63 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
192 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
138 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
113 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 ...
-4
votes
1answer
45 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
127 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
85 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
39 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
48 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
108 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
101 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
623 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
176 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
440 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 ...
0
votes
0answers
39 views

How to get the list of objects being related to object that queries?

I've the following piece of model: Deal -< TradeInstruction // a deal has multiple trade instructions and need to calculate balance for a Deal which is transient and defined as follows: public ...
4
votes
4answers
413 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
673 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
430 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
107 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
378 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
149 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
117 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
322 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
126 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
56 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
345 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
177 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
78 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
286 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
457 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
187 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
213 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
44 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
106 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
164 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
224 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. ...
7
votes
8answers
772 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 || ...
10
votes
3answers
338 views

Is it bad practice for an API object definition to contain 3rd party reference Id's as properties?

Like this: Campaign: type: object properties: id: type: string description: "A GUID identifier" referenceId: type: string description: "A consumers identifier they have used to ...
1
vote
2answers
154 views

Does sending parameters around inside a class suggest that I should refactor to a new class?

I have noticed a pattern when I refactor my code for readability. When I refactor a method into several smaller methods, I often have to introduce parameters which sometimes (too often) makes the code ...
186
votes
16answers
15k views

When using the Single Responsibility Principle, what constitutes a “responsibility?”

It seems pretty clear that "Single Responsibility Principle" does not mean "only does one thing." That's what methods are for. public Interface CustomerCRUD { public void Create(Customer ...