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.
                289 questions
            
            
            
                1
            
            vote
        
        
            
                2
            
            answers
        
        
            
                224
            
            views
        
        
            
            
            
        Interface with member interface?
                    Let's say I am coding an C++ application which needs to drive some motors with some hardware interface (USB, Serial...).
There are several kinds of motors, which expose the same services, but with ...
                
            
       
        
            
                0
            
            votes
        
        
            
                2
            
            answers
        
        
            
                249
            
            views
        
        
            
        How does the DAO design pattern decouple the persistence layer from other layers?
                    I have a few questions about the DAO design pattern.
Let's suppose that I'm building a simple 2-tier MVC web app with a presentation layer and a persistence layer that communicates with a relational ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                216
            
            views
        
        
            
            
            
        DTOs and Single-responsibility principle
                    I'm developing a PHP application and trying to understand DTOs in context of single-responsibility principle. Being more specific, is it a bad practice having helper methods like toArray(), getValue(),...
                
            
       
        
            
                2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                157
            
            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 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                5
            
            answers
        
        
            
                598
            
            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 ...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                224
            
            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.
...
                
            
       
        
            
                0
            
            votes
        
        
            
                1
            
            answer
        
        
            
                181
            
            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, ...
                
            
       
        
            
                0
            
            votes
        
        
            
                4
            
            answers
        
        
            
                274
            
            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 ...
                
            
       
        
            
                1
            
            vote
        
        
            
                4
            
            answers
        
        
            
                407
            
            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 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                4
            
            answers
        
        
            
                2k
            
            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 ...
                
            
       
        
            
                -2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                126
            
            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 "...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                408
            
            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 ...
                
            
       
        
            
                5
            
            votes
        
        
            
                4
            
            answers
        
        
            
                574
            
            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 ...
                
            
       
        
            
                3
            
            votes
        
        
            
                3
            
            answers
        
        
            
                3k
            
            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, ...
                
            
       
        
            
                3
            
            votes
        
        
            
                2
            
            answers
        
        
            
                291
            
            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 ...
                
            
       
         
         
        