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.

Filter by
Sorted by
Tagged with
0 votes
3 answers
144 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 ...
helvy91's user avatar
  • 29
-5 votes
1 answer
75 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 ...
Łukasz R's user avatar
2 votes
2 answers
135 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)....
Paul Kertscher's user avatar
0 votes
1 answer
69 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 ...
Gaz's user avatar
  • 159
0 votes
0 answers
132 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 ...
030's user avatar
  • 518
2 votes
0 answers
214 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 ...
MADforFUNandHappy's user avatar
3 votes
2 answers
116 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 ...
keelerjr12's user avatar
  • 1,219
12 votes
5 answers
711 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 ...
Dennis's user avatar
  • 8,227
0 votes
2 answers
218 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 ...
Maxime's user avatar
  • 310
7 votes
4 answers
627 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 ...
BPL's user avatar
  • 455
4 votes
4 answers
681 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 ...
Dennis's user avatar
  • 8,227
9 votes
7 answers
2k 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 ...
James Wood's user avatar
2 votes
4 answers
1k 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 ...
Pop's user avatar
  • 219
0 votes
1 answer
157 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....
Joao Vitor's user avatar
0 votes
1 answer
2k 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 ...
Sandman's user avatar
  • 33
69 votes
12 answers
15k 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 ...
Paul Kertscher's user avatar
3 votes
3 answers
186 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 ...
manoftheyear's user avatar
1 vote
1 answer
319 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 ...
user avatar
7 votes
1 answer
3k 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 ...
Husain's user avatar
  • 309
0 votes
2 answers
508 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 ...
undermind's user avatar
  • 117
0 votes
1 answer
115 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 ...
curious-cat's user avatar
4 votes
3 answers
1k 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 ...
Bob's user avatar
  • 151
2 votes
1 answer
368 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 ...
Natan Rubinstein's user avatar
0 votes
1 answer
100 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 ...
Tauqeer's user avatar
4 votes
1 answer
446 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 ...
Patrik Bak's user avatar
5 votes
6 answers
1k 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 ...
charlieshades's user avatar
-2 votes
2 answers
319 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,...
Narender Parmar's user avatar
1 vote
5 answers
425 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: ...
Oleg Kovalov's user avatar
0 votes
1 answer
56 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 ...
Ferenc Dajka's user avatar
1 vote
1 answer
164 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 ...
vin's user avatar
  • 267
0 votes
1 answer
277 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 ...
Yeldar Kurmangaliyev's user avatar
2 votes
5 answers
318 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. ...
IntelliData's user avatar
9 votes
8 answers
2k 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 || ...
gvk's user avatar
  • 335
9 votes
3 answers
776 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 ...
jezpez's user avatar
  • 323
1 vote
2 answers
176 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 ...
Chris Wohlert's user avatar
213 votes
16 answers
23k 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 ...
Robert Harvey's user avatar
7 votes
2 answers
961 views

How do I make this Open/Closed example also obey Single-Responsibility?

This is a simple example, but it reflects a tension between SOLID principles that I often find myself struggling with. A popular example of the Open/Closed Principle (e.g. [1], [2]) imagines that you ...
Standback's user avatar
  • 1,310
2 votes
2 answers
3k views

How to refactor functions?

Let's say I want to have a function to load a project's data from both a json and a file path, the first idea which comes to my mind would be having a couple of functions such as: def ...
BPL's user avatar
  • 455
3 votes
3 answers
995 views

Single Responsibility, Api Methods, Error Logging, and Helper Classes

I'm getting in a heated debate about the Single Responsibility Principle and some code that I wrote. I feel strongly that I am right and would like some unbiased feedback. Basically, we have decided ...
christo8989's user avatar
13 votes
4 answers
1k views

Large class with single responsibility

I have a 2500 line Character class that: Tracks the internal state of the character in the game. Loads and persists that state. Handles ~30 incoming commands (usually = forwards them to the Game, but ...
user35358's user avatar
  • 301
4 votes
2 answers
2k views

Code Design : microservice - Services Losing Single responsibility Principle

I am trying to implement Microservice to understand the architecture and how communication works. Many articles state that Services should follow the Single Reponsibility Principle, but it's kinda ...
user784530's user avatar
2 votes
1 answer
547 views

Is dispatching a query and rebuilding a query result in the same class a violation of the Single Responsibility Principle?

In my own variation of the command/query (CQRS) pattern, I define the following for a query handler: public interface IQueryHandler<in TParameter, TResult> where TParameter : IQuery<TResult&...
TheOtherTimDuncan's user avatar
10 votes
4 answers
3k views

What are the responsibilties of the main in object oriented programming?

I'm new to object oriented programming and I don't understand what's the purpose of the main. Yes, I read that it's the "entry point" of the program but what I don't understand is what should be in ...
Tripola's user avatar
  • 221
14 votes
4 answers
952 views

When following SOLID, are reading and writing files two separate responsibilities?

I'm just starting to explore SOLID and I'm unsure if reading from files and writing to files are the same responsibility. The target is the same file type; I want to read and write .pdf's in my ...
Kites's user avatar
  • 151
2 votes
3 answers
2k views

How and to apply Single responsibility principle correctly? [duplicate]

From Wikipedia on Single responsibility principle SoC ... class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be ...
Roman Toasov's user avatar
3 votes
1 answer
419 views

CQRS: how granular should the queries be?

I have a system that uses CQRS with the Queries written using Dapper. It's worked out well, except that there has been a proliferation of query classes that do almost the same thing. The downside of ...
NMrt's user avatar
  • 479
6 votes
2 answers
148 views

Should I use a huge delegator to keep my code decoupled?

I am currently learning to apply the SRP and decouple code. But I found that having a lot of small classes blows up constructors of my classes. And it feels like code that uses another module of my ...
JDurstberger's user avatar
3 votes
1 answer
111 views

Where does the logic belong to respect SRP here?

I'm working on a simple class to get a token from an API. As simple as it is, it has different aspects. A connection to the API is needed for this to work at least the first time. Credentials are ...
Steve Chamaillard's user avatar
2 votes
1 answer
1k views

When to create an in-memory object to manage repository records?

Suppose I have a conceptual Ledger that is populated with Line Items. Assume that Line Items themselves are stored in some type of persistent storage. The ledger is shown to the user who can add/...
Dennis's user avatar
  • 8,227
2 votes
1 answer
1k views

Do having a method that process both GET and POST requests violates SRP?

I'm starting with Zend Framework 3 and I saw an example on the tutorial that goes like this: public function addAction() { $form = new AlbumForm(); $form->get('submit')->setValue('Add');...
Christopher Francisco's user avatar