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.
Questions tagged [single-responsibility]
285 questions
39
votes
8 answers
Does adding a return type to an update method violate the "Single Responsibility Principle"?
I have a method that updates employees data in the database. The Employee class is immutable, so "updating" the object means actually to instantiate a new object.
I want the Update method to return a new instance of Employee with the updated data,…

Michael Haddad
- 2,697
7
votes
3 answers
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 Responsibility Principle, a class must be responsible…

korima
- 245
5
votes
6 answers
Problem understanding the Single Responsibility Principle
The SRP seens fairly reasonable when you first look at it. Every class should have one reason to change. Every class should take care of one thing. Right. But let's see this class:
Employee {
CalculatePay();
Save();
DescribeEmployee();
…
4
votes
3 answers
Separate the renderer from the business model
I have a small responsibility separation issue that I hope someone can clarify. I have a small model composed by 2 classes: GameBoard and GamePiece, and the obvious relationship is that a GameBoard can have several GamePieces.
In the application I'm…
3
votes
2 answers
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 outputs the cached data.
Should the function that…

moonman239
- 2,053
3
votes
0 answers
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 of fixed-column length, delimited by a char. You…

JorgeeFG
- 669
2
votes
4 answers
Single responsibility of a function
I would like to find out if I understand single responsibility principle correctly.
The function below is suppose to return user ID store in database by using the SAM account name pass into it.
Look at the commented codes below, is it true about the…

Pop
- 219
2
votes
1 answer
Single Responsibility Principle - Setting position of WinForm in MVC
Should code that positions a form be in a seperate class or within the form itself. It is assumed, that there will be only one form using it.
A class definitely encapsulates the behavior and the state, but maybe it is unnecessary indirection in this…

John
- 358
2
votes
1 answer
Something confusing about Single Responsibility Principle
1)
In fact if two responsibilities are always expected to change at the
same time you arguably should not separate them into different classes
as this would lead, to quote Martin, to a "smell of Needless
Complexity". The same is the case for…

user1483278
- 1,131
- 1
- 10
- 14
0
votes
1 answer
In SRP POV, Should converting raw data to an object be in a dedicated method?
I have a function that retrieves raw data from the database and returns an object which represents this data.
Should the conversion between the raw data and the object be written in that method or should I dedicate a separate method for the…

Michael Haddad
- 2,697
-5
votes
1 answer
Naming abstract class for object creation and update views
How can I name an abstract class that has a common part of view of my two panels? One of them is for creating an object and the other one is for updating it. I want to keep these view in different classes to maintain SRP.

Łukasz R
- 1