In object-oriented programming, the single responsibility principle (srp) states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
11
votes
5answers
405 views
Code repetition vs multi responsible method
I try to follow the Single Responsibility Principle (SRP) and also to omit Code Repetitions. However there are often places where there are code repetitions that are nothing more than code blocks of ...
1
vote
1answer
79 views
Discovering functionality from parallel class hierarchy
I have an abstract syntax tree which I want to compile down to different representations. I am now struggling to arrange the classes in a way that new representations can be added easily.
The easiest ...
3
votes
1answer
123 views
Designing and refactoring of payment logic
Im currently working on an application that helps users to coordinate dinner clubs and all related accounting. (A dinner club is where people in a group, take turns to cook for the rest and then you ...
5
votes
2answers
224 views
Does increasing the number of classes increase code complexity? [duplicate]
To illustrate the question, let's say we have two programmers of comparable skill that both solve the same problem. The code they turn out has roughly the same lines of code, but one programmer uses 5 ...
5
votes
2answers
325 views
Is it good to have an interface plenty of methods which belong to different concepts, just to preserve the Liskov's Principle?
I'm currently studying a course based on Software Design and I had a discussion in class with my professor and some classmates about a problem represented by the next scenario:
Scenario
Imagine ...
6
votes
3answers
461 views
Is Domain Entity violating Single Responsibility Principle?
Single responsibility ( reason to change ) of an entity should be to uniquely identify itself, in other words, its responsibility is to be findable.
Eric Evan's DDD book, pg. 93:
most basic ...
5
votes
3answers
177 views
How do I design a DAL when I have to deal with relationships?
Say I'm developing a bug tracker, where a ticket belongs to at most one milestone, and a milestone can have many tickets. When a milestone is deleted (from the database), all tickets associated with ...
0
votes
1answer
119 views
Design patterns to avoiding breaking the SRP while performing heavy data logging
A class that performs both computations and data logging seems to have at least two responsibilities. Given a system for which the specifications require heavy data logging, what kind of design ...
19
votes
5answers
1k views
How do I prove or disprove “god” objects are wrong?
Problem Summary:
Long story short, I inherited a code base and an development team I am not allowed to replace and the use of God Objects is a big issue. Going forward, I want to have us re-factor ...
6
votes
6answers
646 views
What are the practical ways to implement the SRP?
Simply what are the practical techniques people use to check if a class violates the single responsibility principle?
I know that a class should have only one reason to change, but that sentence is ...
3
votes
2answers
396 views
How do you follow the single responsibility principle in classes responsible for behaviour?
I have many classes in my application responsible for behaviour- views, controllers, models, network- often the state of one class or system depends on another and I'm finding that classes that are ...
-2
votes
1answer
231 views
Single Responsibility Principle: Responsibility unknown [closed]
I store sessions in a SessionManager. The session manager has a dependency to ISessionPersister.
SessionManager
private readonly ISessionPersister sessionPersister;
public ...
7
votes
3answers
1k views
IValidatableObject vs Single Responsibility
I like the extnesibility point of MVC, allowing view models to implement IValidatableObject, and add custom validation.
I try to keep my Controllers lean, having this code be the only validation ...
37
votes
6answers
7k views
Single Responsibility Principle - How Can I Avoid Code Fragmentation?
I'm working on a team where the team leader is a virulent advocate of SOLID development principles. However, he lacks a lot of experience in getting complex software out of the door.
We have a ...
2
votes
1answer
174 views
Composite-like pattern and SRP violation
Recently I've noticed myself implementing pattern similar to the one described below. Starting with interface:
public interface IUserProvider
{
User GetUser(UserData data);
}
GetUser method's ...
4
votes
2answers
196 views
How to deal with variables when extracting methods in to smaller methods?
This is an abstract question to clarify a refactoring concept in the ruby language. Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish ...
4
votes
3answers
426 views
Single Responsibility Principle Implementation
In my spare time, I've been designing a CMS in order to learn more about actual software design and architecture, etc.
Going through the SOLID principles, I already notice that ideas like "MVC", ...
2
votes
3answers
209 views
May I give a single class multiple responsibilities if only one will ever be reusable?
To the extent that I understand the Single Responsibility Principle, a SINGLE class must only have one responsibility.
We use this so that we can reuse other functionalities in other classes and not ...
8
votes
2answers
250 views
When following SRP, how should I deal with validating and saving entities?
I've been reading Clean Code and various online articles about SOLID lately, and the more I read about it, the more I feel like I don't know anything.
Let's say I'm building a web application using ...
8
votes
5answers
493 views
Is SRP (Single Responsibility Principle) objective?
Consider two UI designers who want to design "user attractive" designs. "User attraction" is a concept that is not objective and only resides in the mind of designers. Thus designer A could for ...
7
votes
1answer
145 views
Separation of Concerns when adding new types
I have a system I've been working on this week where I'm having a hard time balancing separation of concerns with easy extensibility. I'm adding new types to the system, and it feels like shotgun ...