Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

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
1 vote
1 answer
87 views

Refactoring Processor classes

I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...
Tim Kirkwood's user avatar
2 votes
5 answers
411 views

What exactly is the single responsibility principle? [duplicate]

I've generally understood the SRP to roughly mean: Each class should do one thing Exactly what "one thing" is is up for debate. However, I've recently seen claims that the entire SRP has ...
ScottishTapWater's user avatar
0 votes
1 answer
103 views

Shopping Cart Design with SRP: Handling Cart Creation and Update Separately

I'm working on designing a shopping cart system that respects the single responsibility principle. However, I'm facing a challenge when it comes to handling cart creation and updating separately. ...
Thiago Dias's user avatar
0 votes
1 answer
102 views

Validation logic dependencies and separation of concerns

I am going back and forth on an aspect of our FluentValidation and MediatR pipeline behavior implementation. We receive requests which, in a Mediator pattern, are mapped to command or query objects, ...
BJ Safdie's user avatar
  • 103
0 votes
4 answers
252 views

Single responsibility principle - Classes with operator overload

I've been reading a bit through Clean Code and I came across the Single Responsibility Principle. The principle states that every class should have only one responsibility. An example taken from ...
user8469759's user avatar
1 vote
4 answers
381 views

Is there any intent behind SRP other than SoC

Edit based on responses so far I am starting with an edit so as to save future contributors from going down the same path others have. I am only interested in contributions that stick to the exact ...
Ash's user avatar
  • 219
2 votes
4 answers
1k views

My concrete classes only have a constructor. Everything else comes from an abstract class. Is this bad practice?

I think that I've taken the Open-Closed and Single Responsibility principles too far. Previously, I had one huge static class containing every method that has C# talk to stored procedures on my SQL ...
J. Mini's user avatar
  • 1,007
-2 votes
1 answer
100 views

Does my class violate the Single-Responsibility Principle? [duplicate]

Goal: I am learning about SOLID principles and trying to refactor Gilded Rose code, in order to make it fresh and clean. What I have done: I have created an AbstractItem class as follows, which "...
tail's user avatar
  • 101
1 vote
1 answer
209 views

Can I separate methods into different classes by passing in constructor properties from one class to another?

I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare ...
Kevin Greetham's user avatar
5 votes
4 answers
459 views

Does my outer class adhere to the Single Responsibility Principle?

I often write front end apps with a generic MVC pattern. I use javascript but this questions is language independent and relates to OOP as a whole. I struggle to understand the SRP principle and I ...
Kevin Greetham's user avatar
3 votes
3 answers
1k views

Is a method named createOrUpdate() violating the single responsibility principle? Should I split into create() and update()?

I work developing software, and very often I find inconsistency in the company's code. The thing is, there is a method named createOrUpdate(), and this method basically does what its name says, ...
Warlock's user avatar
  • 59
3 votes
2 answers
248 views

Under the single-responsibility principle, should caching data be a separate function from returning the data?

Suppose I have a program that returns data from an API. If its cache of the data is too old, the program downloads more data from the API, caches it, and outputs the new data. Else, the program ...
moonman239's user avatar
  • 2,063
3 votes
3 answers
715 views

In testing is making asserts in cleanup bad?

As a learning excercise, I decided to take a hand on Test Driven Development. Now I decided that there is a test I want to make; check if database connection doesn't leave any unsaved changes. The two ...
vakus's user avatar
  • 133
0 votes
2 answers
178 views

How to refactor code so that a facade class could be decoratable?

I've got a class that is a facade class (encapsulates complex-ish behaviour for reusability). It has a function called manage (the class is called Manager): function manage() { $entityBuilder = '...
pro100tom's user avatar
  • 449
0 votes
1 answer
206 views

std::string violates Single Responsibility Principle? [closed]

I recently attended a C++ talk on SOLID principles and the presenter provided std::string as an example that violates SRP. I wasn't quite able to comprehend why that was the case. From what I ...
Zoso's user avatar
  • 241
-2 votes
2 answers
178 views

Guidance on naming methods that check data quality and then executes logic [closed]

I'm writing boolean methods that do a data quality check and then performs logic. such as isRecordValidAndIsUserPrivilaged. these methods checks the record validity, and then checks the user's access )...
PartOfTheOhana's user avatar
1 vote
2 answers
131 views

How to maintain cohesion, loose coupling, and SRP when building a reporting tool?

I'm building a reporting tool with three core layers: Extract data from a database Transform this data to compute business metrics Display these metrics in a report (a heavily formatted Excel export ...
Myccha's user avatar
  • 119
2 votes
2 answers
75 views

Should client application clean the data that a server application can not internally process? (In SOA Systems)

Scenario : For some (comment) text field the server application is internally throwing errors when the field contains contains some specific characters. Where should the removal of characters be ...
jimjim's user avatar
  • 873
0 votes
1 answer
442 views

Clean code: Register listeners inside class handling events, or outside?

I'm writing a Java program with a custom event manager, which is of course the observer pattern. Should the calls to add event listeners/handlers be in the classes that listens/handles the events ...
user1902689's user avatar
0 votes
1 answer
63 views

For a spa application should request be follow the "single responsiblity" idea or is it better to combine data?

Well in a page in our spa application we need to request some dynamic data from the server. Besides this data for display purposes we also need to request explanations of the columns from the data (...
paul23's user avatar
  • 1,091
3 votes
2 answers
631 views

How to use visitor pattern when objects change frequently

It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently. What if the objects are changing too though? For example we ...
Ehsan Poursaeed's user avatar
1 vote
1 answer
166 views

Abstract Base Class decides which type of child class to create at runtime

I have an Abstract Base Class AbstractModel class AbstractModel { public: struct predictionStructure{}; virtual predictionStructure predict(CompanyLib::Matrix<double> data) = 0; std::...
casey ryan's user avatar
1 vote
5 answers
2k views

Clean architecture, Login UseCase with OAuth breaking Single responsability principle

I'm building a login system using OAuth to integrate with various social networks. The flow is very simple, first, the user is redirected to their social network to grant permission to read the ...
Thiago Dias's user avatar
1 vote
1 answer
243 views

SRP, command pattern and design problem

I'm refactoring a code base to have something more easier to read and follow SRP. However I'm at the point I'm unsure what the best design is. Currently it looks like this: A thread receives a "...
Cromm's user avatar
  • 119
0 votes
1 answer
209 views

Why doesn't Laravel actively support Service Classes?

There must be a good reason for this. Laravel's default pattern makes no use of Service Classes... but the Laravel community's best practices is for business logic to be stored in them. Laravel's ...
Django Reinhardt's user avatar
-1 votes
2 answers
100 views

Contemporary Design and One-to-One Relationships: code-first vs data-base first approaches

After reading, Does it ever make sense NOT to condense one to one relationships?, I wanted to take the question further with regards to contemporary design of entities, front-end code and controllers. ...
8protons's user avatar
  • 1,369
0 votes
1 answer
463 views

Mixing an API server and a background worker

What are your thoughts on having a service/process be both an API server and a background worker, consuming messages off a queue like SQS? I have typically kept these two separate to keep single ...
n00b's user avatar
  • 111
6 votes
6 answers
468 views

Should a Car object be responsible for checking if it is able to run on certain Road objects?

I have 2 kinds of objects in my system, Car and Road. A Car can be of various types and have properties like tire, tire size, engine, etc. A Road can be of multiple types and have properties like ...
Thiago's user avatar
  • 169
2 votes
1 answer
112 views

Guidelines for using extensions in Swift

The other day, I came across this question on StackOverflow. In short, the user who asked the question wanted to extend a class from a third-party library to implement the Codable protocol, but ...
TallChuck's user avatar
  • 152
0 votes
1 answer
582 views

Expose or consume API REST?

I am preparing the software architecture for my client project based on APIs REST The idea is that any data exchange between my client and his partner will be via API REST call The specification is ...
Benhassine Mohamed's user avatar
31 votes
10 answers
6k views

Does logging inside a class violate the SRP?

I wrote a class that takes a Logger class as one of its arguments: class QueryHandler: def __init__(self, query: Query, logger: Logger) -> None: self.query = query self.logger =...
pstatix's user avatar
  • 1,027
1 vote
1 answer
151 views

What is the granularity of the SRP of functions? [duplicate]

If a function is being used to process incoming results, I believe an SRP violation exists if it contains all the logic: def process_response(response): '''Process the results of the web request''' ...
pstatix's user avatar
  • 1,027
1 vote
3 answers
498 views

Too much parameter in a class' constructor, when trying to conserve the dependency injection principle [duplicate]

I am developing a simulator of a bank software system, where each operation (deposit, withdraw, transfer, ...) is just a string. I have 5 main classes : Bank where bank accounts are stored. ...
X Y's user avatar
  • 311
0 votes
2 answers
49 views

Should an Express error handler be used to send HTTP 4xx responses?

In other words, should the raising of an HTTP 4xx code be considered an error, and should the job of sending an HTTP 4xx code to a client be delegated to an error handler? Or is it simpler to just ...
Asker's user avatar
  • 109
2 votes
3 answers
314 views

When does a function violate the SRP?

I have a function that was written because several methods used the same sequence of code so an abstraction was useful. The function takes a string representing the path to a registry key and then a ...
pstatix's user avatar
  • 1,027
0 votes
2 answers
953 views

Good design for a class with multiple methods to test but one public method

I've been trying to refactor some existing code which is in essence a giant nested procedural call inside what should otherwise be an object oriented architecture. The entry point to the relevant code ...
User's user avatar
  • 23
3 votes
1 answer
67 views

How to handle changes to local and global representation of an Entity in a distributed environment?

I'm a developer for a retail enterprise IT department, and am currently stuck on the following scenario: Department A is responsible for a CRUD service that's used for handling stores - so when our ...
sigsegv's user avatar
  • 99
1 vote
1 answer
532 views

In which layer should I load views on a Clean(ish) architecture?

I am trying to organize my architecture following the clean architecture while using some common practices/frameworks. I'm writing in PHP, but have no problem with other languages. The flow of my app ...
Erick de Azevedo Lima's user avatar
1 vote
2 answers
174 views

How does one choose where to place logic which converts data between two formats/representations?

Suppose I have two "modules", A, and B (I'm choosing not to use classes, because you generally can't create an instance of a module, which makes this question simpler). These modules contain ...
taylorthurlow's user avatar
8 votes
3 answers
546 views

Breaking up a class with too many responsibilities

I'm looking for advice on my specific problem, how to break up a class, Basket, that has too many responsibilities. Currently, it does three things: Keeps track of the products in the basket: ...
Adam Griffiths's user avatar
-3 votes
2 answers
111 views

Do classes that set, get and calculate data follow the S in SOLID?

Supposing I live in a country where every car brand has a different tax rate, and I have a base class called Car public class Car{ public string CarType { get; set;} public int Year {get; set;}...
ThePorcius's user avatar
2 votes
3 answers
785 views

How to not violate the single responsibility principle?

Let's say I'm writing a class that tracks a single stock ticker. In this simplified example, the StockTracker class holds a string that tells me the trend direction and a variable window that holds x ...
jgv115's user avatar
  • 139
8 votes
2 answers
756 views

Data handling in SRP (single responsibility principle)

TLDR; Robert C. Martin adviced here: http://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html to split the multi responsibility classes into "single reason to change"...
FrankM's user avatar
  • 191
0 votes
1 answer
215 views

How to maintain SRP with a chain of async functions?

For code maintainability I understand that it is generally better to have code structured like this: void abc() { a(); b(); c(); d(); } Instead of like: void abcd() { a(); bcd(...
Evan La Fontaine's user avatar
0 votes
3 answers
604 views

How to arrange expected result model for test in a cleaner,readable way when the model contains many properties

In one of my projects I saw wrapping the expected results as a static variable in non static class. The reason for doing so is to make the code more readable, so that the massive expected result model ...
Anjo's user avatar
  • 215
-1 votes
1 answer
416 views

SRP for MVC controllers

I am trying to design an application that will be a REST API following MVC. For now ,I have 2 main features: Projects and Tickets associated to Projects. I would like to apply SOLID principles, and I ...
NeoChiri's user avatar
  • 155
0 votes
2 answers
205 views

Avoiding sequential coupling while maintaining separation of concerns

Got a desktop application that interacts with some stateful third party web APIs. Its an interactive application, at some stages it has to halt execution and prompt for user input based on responses ...
boarnoah's user avatar
1 vote
4 answers
394 views

Is there multiple definitions for responsibility of class?

In the book UML 2 and the Unified Process from Arlow and Neustadt has been told: Analysis classes should have 3 to 5 responsibilities But as you know we have the SRP that tells us something else!! ...
flexibleHammer's user avatar
1 vote
1 answer
89 views

aggregate data for complex API call without coupling modules to parameter object

I am working with an API that is used for registering bookings in a ticket system. Some of the calls I have to make take complex XML objects as arguments. Some data points in these objects have to be ...
Cornelius Carstens's user avatar
4 votes
4 answers
892 views

Relationship between inheritance and single responsibility principle

Example 1: Let me assume that I have a base class A. Class B extends Class A (Class B is a derived class). Can I conclude, Class B doesn't obey single responsibility principle since it uses the ...
Dharma Teja Bandaru's user avatar

1
2 3 4 5 6