Skip to main content
The 2024 Developer Survey results are live! See the results

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.

2 votes
1 answer
126 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
422 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
148 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
116 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
254 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
388 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,017
-2 votes
1 answer
101 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
265 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
486 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
  • 69
3 votes
2 answers
251 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
788 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
211 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

15 30 50 per page
1
2 3 4 5
20