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.

learn more… | top users | synonyms (1)

1
vote
1answer
50 views

How to compute Pricing of Product & Options based on User Option Selection and Pricing per Option

I am building a service for pricing options of a product and for pricing the product itself when product has various options. Example User selects some X options out of Y options available, where X ...
0
votes
1answer
78 views

What is the responsibility of a class 'calling' other classes as workflow?

What if I have a class X that does the following: Read a file (within its own class). Parses the file by calling a Parse class Processing the parsed file by calling a Process class Outputting by ...
5
votes
1answer
83 views

How do I more effectively design this per its intended design while ensuring I'm meeting SOLID design principles?

I know what SRP is, but am questioning my current design of an object I call an entity. Below is a picture of the design I am referring to. If I shift the code from the GeometricInformation and ...
1
vote
0answers
22 views

Does RaceDataFacade violate the single responsibility principle?

I have heard, that each class should always just be responsible for a single purpose, otherwise you should rethink your design. So here are the concerned classes: WebSocketController: provides ...
1
vote
2answers
134 views

When decoupling methods is not a good idea?

It's a discussion about follow very strictly the SRP (Single Responsability Principle) vs. be more flexible when you write simple codes, like setting or getting properties values, even out of a direct ...
3
votes
3answers
229 views

Single Responsibility - is this class doing too much?

I'm redesigning one of my programs which performs certain actions on processes of interest (known as "Monitored Processes" in my program). Some actions I always need to do on those processes are: ...
3
votes
2answers
94 views

Is it a bad idea to put externally dependent logic in ORM classes?

Case in point in Entity Framework, but this is a design question which has applicability to any ORM. In the current application we have a couple of ORM data classes which do stuff not directly ...
56
votes
11answers
6k views

Does this class design violate the single responsibility principle?

Today I had an argument with someone. I was explaining the benefits of having a rich domain model as opposed to an anemic domain model. And I demoed my point with a simple class looking like that: ...
-1
votes
1answer
41 views

SRP. Save to repository when edit. Internally or externally? [closed]

For example: class Data { private String field1; private String field2; public void someEditMethod() {} } class DataRepository { public void save(Data data) { // save to DB ...
2
votes
1answer
175 views

Helper methods of a particular class [closed]

Let's say I have a class that needs some helper methods to do its work. The number of helper methods starts to grow and the size of the class also starts to grow a lot. How should I handle this ...
3
votes
1answer
98 views

Single Responsibility Principle : Proxy Pattern for refactoring

However, in cases where the tests did not force the separation, and the smells of Rigidity and Fragility become strong, the design should be refactored using the Facade or Proxy patterns to ...
6
votes
4answers
307 views

Class design dilemma: Encapsulation vs Single Responsibility/Separation of Concerns

I'm working on a class that represents an object with multiple representations - one is an XML type representation used by an automatic ordering system, the other is a POJO-based representation used ...
3
votes
2answers
181 views

Where to put very specialised functions which heavily use one class?

I have a class which is centred around lower-level methods, to make this class much more useful it would be great to put some middle or higher level methods (i.e. methods which make a series of calls ...
12
votes
5answers
766 views

How to avoid violating the SRP in a class to manage caching?

Note: The code sample is written in c#, but that shouldn't matter. I've put c# as a tag because I can't find a more appropiate one. This is about the code structure. I'm reading Clean Code and trying ...
5
votes
2answers
170 views

Do I violate the Single Responsibility Principle with my multi-purpose AST Class?

I am writing a compiler, for which I devised a rather classic architecture: it's composed of sequential passes piped together, starting with a lexer and a parser, continuing with a macro processor, ...
2
votes
1answer
113 views

Explain ServiceLocator pattern of ZF2

I am looking at this example: http://framework.zend.com/manual/current/en/user-guide/database-and-models.html Relevant excerpt from above: class AlbumController { public function ...
2
votes
3answers
146 views

Single responsibility policy problem

I'm a bit stuck using the single responsibility policy. I have a class named Parser, which can be configured to parse input a certain way. For the sake of convenience I will limit the configuration ...
1
vote
1answer
94 views

Stuck on design when attempting to create an object store

I'm working on a small scale API project but as it will be used and maintained by people that are not Software Engineers to trade I am attempting to keep the design as separate and identifiable as ...
1
vote
3answers
141 views

How to understand if a property is a member of a class or I have to create a different class that holds it?

Sometimes when you create a class you can add there several properties (new data members) that you are not certain if you want to do or not. For example, I have a casino slots game. I have tiles and ...
3
votes
2answers
148 views

SRP and Getters/Encapsulation

I recently watched this presentation of Robert C. Martin about the Single Responsibility Principle: https://www.youtube.com/watch?v=Gt0M_OHKhQE He presents an Employee class with multiple ...
0
votes
2answers
81 views

How to better define SRP and “wholesome” objects? [duplicate]

Assume you have a class. It can really be any class that defines a domain concept like an employee, a product on an e-commerce site, or a car. One of those examples that are oldies but goodies. ...
2
votes
2answers
188 views

How to avoid god controller classes and keep single responsibility principle?

The task is to make a migrator from Old DB to New DB using OOP Single Responsibility Principle. My problem is how can I make this without making the controller a God Class or breaking the single ...
2
votes
2answers
193 views

Why is modularity a good idea? [closed]

I have a programmer on my team who wants to take all the control flow logic for handling events sent by any module and put it all in a single file, because they think it will make an already-complex ...
0
votes
0answers
25 views

SRP in MVVM's ViewModel

I have a question about Single Responsibility Principle in MVVM. I'd like to create a group of views for Warehouse Mgmt. Software. They would be connected to properties from my document which should ...
3
votes
1answer
61 views

Can I resolve an issue with SRP, SOC that prevents object initialization via constructor?

In OOP, I can populate (initialize) an object using constructor injection at object creation time, or setter injection, after creation time. I like the idea of populating object at creation time via ...
2
votes
1answer
75 views

Why is SRP using the class construct to contain a responsibility opposed to using any other OOP entity?

SRP states ... There should never be more than one reason for a class to change. But why a class? Why not use granularity of a function/method? What instead of separating my functionality into ...
2
votes
2answers
167 views

Does it break SRP to have concerns of data handling and object mapping inside a single class, as part of the DataMapper pattern?

Summary I want to look into separating the concern of "creating a populated object from database", to use inside my application. DataMapper pattern seems to be doing just that for me. DataMapper ...
0
votes
3answers
163 views

How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?

I'm refactoring an old app to use dependency injection.n I'm pretty new to DI. I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to ...
4
votes
1answer
139 views

Where to initialize objects

I have an BallEntity class that is part of a game that uses a Entity Component System architecture. This class have 'components' that are like the attributes of that class. I create and initialize ...
1
vote
2answers
65 views

Responsibility of an ESB

When using an enterprise service bus, is it responsible for; a. the successful delivery of a message to a consuming application b. to successfully deliver a message until the application's ...
3
votes
2answers
1k views

Class becoming God Object what pattern to use

I am developing Android app and my MainActivity is becoming God Object. By the way native Activity class implementation is some sort of God Object already. The problem is that my activity class is ...
3
votes
2answers
880 views

Difference between Single Source Of Truth and Single Responsibility Principle?

So I just found out about the term single source of truth while watching video series about programming code interviews. From what I understood it meant that the single source of truth is an ...
2
votes
1answer
97 views

Pick dynamically the right Factory Class with Inversion of Control

I have a TreeView and I want to enable the context menu when clicking with the right mouse button. It is composed by items from different classes, but they all share the same base class. So, I was ...
2
votes
4answers
229 views

When should I mix functions with data in a class?

Based on some questions I asked (1, 2,3), I am frequently suggested to separate data from functions (because of changes in function, single responsibility, separation of concerns, adopting interfaces, ...
3
votes
1answer
152 views

Is the target of 3 dependencies per class always achievable?

I'm reading the Clean Code book and a chapter says that if a class has more than 3 dependencies is a code smell of that class isn't doing one thing. Or what is the same, it isn't following SRP. I'm ...
3
votes
1answer
101 views

Peculiar architecture interfacing .NET to AutoCAD out-of-process

I have written a set of classes to interact with AutoCAD from an out-of-process .NET assembly, but it seems like my class architecture and interactions are unusual. I am struggling to find a better ...
1
vote
2answers
166 views

Rich Domain Models, Encapsulation, and the Problem of Constructor Over-Injection

I am refactoring an e-commerce web-application, currently working on the UserBasket class, which will have to handle adding or removing items, changing their quantity, getting total amount, total ...
4
votes
2answers
275 views

What principle is violated by having a button do two radically different things or screens act radically different depending on the situation

I've come upon a situation several times in my career when previous developers have done something funny. They will make a control (button) function radically different depending on how the screen ...
14
votes
6answers
3k views

Is logging next to an implementation a SRP violation?

When thinking of agile software development and all the principles (SRP, OCP, ...) I ask myself how to treat logging. Is logging next to an implementation a SRP violation? I would say yes because ...
0
votes
2answers
120 views

Distinguishing Classes: How to catch system behavior in classes (Library System Case)

Suppose a Library System. if I think about Data, I can just distinguish Book, Member classes or at most Author or Publisher... (Are they only classes?), but I have some use cases, scenarios (Borrow, ...
8
votes
4answers
2k views

Is the Single Responsibility Principle applicable to functions?

According to Robert C. Martin, the SRP states that: There should never be more than one reason for a class to change. However, in his book Clean Code, chapter 3: Functions, he shows the ...
0
votes
2answers
156 views

Object oriented Classes and single responsibility [duplicate]

I'm reading a book that explain that it is a good thing that classes have a single responsibility, that is, that they do a single thing. I can understand how to implement this in some cases I ...
2
votes
0answers
90 views

Injecting data processing logic into class

I want find more elegant and appreciate way to inject processors into CommandProcessorDispatcher class. Or it can be another one solution (the goal is separate each command processing logic to ...
0
votes
1answer
97 views

Non-anemic model and SRP

I'm implementing a feature in legacy system right now. Instead of putting all my logic in some dummy application services and having anemic models, I thought I will try to do some OOP this time. I'm ...
5
votes
2answers
203 views

How to avoid “type dispatchers” when working with SOLID

I've realized that since I've been more and more strict about the SOLID principles, my code tends to consist of more pure data objects and a lot of "operator" classes which seems to go against ...
3
votes
2answers
143 views

Service Oriented Architecture - Component Responsibility

Working on an ecommerce project whereby a PHP application (back-end & non-customer facing) is currently responsible for processing an order from checkout stage through to generating profit/loss ...
1
vote
1answer
92 views

How to organize all classes derived from SRP?

As the SRP says, the way to achieve this principle is divide all into smaller. And what you have just made small, make more smaller. As consequence we got more files and my question is about it, how ...
3
votes
2answers
779 views

How do you apply Single Responsibility principle to a repository

I am trying to apply "SOLID" whenever I can and try to use common sense and avoid a pattern when I see that a pattern is creating more problems than it's trying to solve. I don't want to apply a ...
2
votes
0answers
101 views

Is this function violating Single Resp Principle?

public function obtenerColumna($delimitador='', $columna=0, $incluirRepetidos=false, $eliminarEspaciosAdyacentes=true, $filaDesde=0, $filaHasta=0) It obtains a column from a set of records ...
6
votes
3answers
414 views

Application of Single Responsibility Principle on a Button

I have a class that represents a button on the screen. This class has two methods: one for click event; the other for long-click event. Both events do different things. So, according to Single ...