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.

Filter by
Sorted by
Tagged with
0
votes
5answers
157 views

Understanding Open Closed Principle

I am confused understanding Open closed principle. As principle says that, open for extension and closed for modification, My thinking is that if there is a class and if you need to add any new ...
3
votes
4answers
160 views

Relationship between inheritance and single responsibility principle

Example 1: Let me assume that I have a base class A. Class B extends Class A (Class B is a derived class). Can I conclude, Class B doesn't obey single responsibility principle since it uses the ...
1
vote
1answer
77 views

Structuring application to comply with Single responsibility

I have the class AircraftManager that keeps track of a list of Aircraft objects and a list of AircraftListener objects. A DataSource (custom class, not sql related) object retrieves information from ...
2
votes
5answers
243 views

Splitting class responsibilities without exposing private data

I'm struggling to find good ways to split up classes without exposing private data. Most articles I read about SRP seem to ignore how the new classes that take on the separated responsibilities access ...
2
votes
1answer
136 views

Is this SRP violation?

Consider I have a class which represents a tree element. An element can be changed, inspected children elements can be added to it (say trough the add() method). But also I have a class which contains ...
5
votes
3answers
883 views

What does it mean for a method or a function to do one thing? [duplicate]

What does it mean when you say that a method or a function should do only one thing? Can it do a few things as long as it has a cohesive name? Should we avoid routines with the word "and" in them? ...
0
votes
1answer
63 views

How to detect class responsibilities? [duplicate]

Consider following class: public class Foo { public Foo() {} public void Bar(int input) { Console.WriteLine("Working on input ..."); switch(input) { ...
1
vote
4answers
180 views

Feature Envy vs. Single Responsibility Principle: Data class and a validator for it

Let's say I have a class that's a bit more than a pure Data object, i.e. it holds some data and some basic queries about that data. (In this case, it's a class representing a timetable) Now, I want ...
2
votes
1answer
50 views

Should a Mover and Tracker be separate classes to maintain SRP?

I'm doing some Java code practice to better understand the Single Responsibility Principle. Currently, I'm working with a network of data structures, where each structure implements an interface ...
1
vote
1answer
80 views

Controller class for an input dialog

I am learning OOP, concretely Java, by developing a real life business application for aimed for repair shops. I have followed MVC pattern design for GUI elements of my application. I was wondering do ...
11
votes
3answers
2k views

Is there a conflict between YAGNI and SRP?

I my job, I am tasked with the responsibility of improving the code quality. To meet this responsibility I often pair program with developers and conduct sessions on design principles and design ...
0
votes
0answers
27 views

Import many data using dto between multiple modules

I am working on a symfony application where i have complex user data coming through an external json feed. This data is usually a 100MB json feed from which i have to read user data (with all its more ...
1
vote
4answers
178 views

Separating data and behavior in Java

I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and ...
6
votes
4answers
1k views

How to respect Single responsibility principle and use exception handling at the same time?

I am getting confused on how exactly should I be using exception handling inside a class that respects S-Principle. For example consider this code in C#: public class BcryptDecrypt { ...
8
votes
3answers
477 views

Does it violate the Single Responsibility Principle if an object knows how to change itself?

I have worked with examples like a Player object which knows how to change its own state. Another example, is an Invoice object which knew how to calculate its invoice charges using an algorithm. ...
2
votes
2answers
101 views

How can I divide up a database between multiple micro-services in an acceptable way when I have multiple constraints?

We have a pretty big monolith. We're currently looking at carving it up into micro-services. Right now we have a file server micro-service (FS) that handles delivering files to clients based on ...
68
votes
8answers
11k views

How can a class have multiple methods without breaking the single responsibility principle

The Single responsibility principle is defined on wikipedia as The single responsibility principle is a computer programming principle that states that every module, class, or function should have ...
1
vote
2answers
117 views

Does is break SRP to keep incompatible physical units and quantities together in the same class, where quantities describe an object?

I want to design a Crate object. A crate is a wooden box that stores things. I need to be able to keep track of of the following things in regards to this crate: length in inches width in inches ...
1
vote
3answers
194 views

Writing Single responsibility methods [closed]

Let's say we have a typical service class method who does few things, input validation, db object retrieval, some business logic execution and then saving and returning record to user. This is ...
0
votes
1answer
90 views

Granularity of the Single Responsibility Principle [duplicate]

This is a related question and the OP appeared to go with extreme levels of granularity. The answers gave a good overview but I gather it's still somewhat down to personal interpretations/situations ...
51
votes
7answers
11k views

Managing and organizing the massively increased number of classes after switching to SOLID?

Over the last few years, we have been slowly making the switch over to progressively better written code, a few baby steps at a time. We are finally starting to make the switch over to something that ...
0
votes
2answers
127 views

SRP violation confusion based on examples

I am trying to gain better understanding on SRP and when I was checking out a Pluralsight video by Scott Allen, I saw code like this: https://github.com/OdeToCode/cs-fundamentals/blob/master/src/...
0
votes
1answer
965 views

Parsing and validation of a csv file

I am trying to create a library where I need to validate and parse a file in a CSV-like format and then use this data to generate a Tree data structure. At the moment I split the process into two ...
3
votes
1answer
199 views

How to make updates to data and return list of updates without breaking Command query separation or DRY?

I have a use case to make updates to a slightly complex JSON object and then return the list of changes made (not the updated data). The process of finding the list of changes is extremely similar to ...
3
votes
1answer
144 views

Way to hide logic behind class for better readability of method and refactor class to follow SRP

I have an algorithm to create a version for an entity and then I save that version against below 2 entity: 1) Variant 2) Category interface IEntityVersion { string GetVersion(); } public class ...
2
votes
1answer
172 views

Should gravity sources pull objects or objects pull themselves to gravity?

I'm doing a project in unity where I turn off the general gravity and implement it myself. What I'm trying to acheive is to have GameObjects be affected by several gravity sources on every tick. I got ...
5
votes
3answers
392 views

How to avoid duplication of types in MVVM

I'm learning the MVVM pattern and something that comes up often is a duplication of data-types. Say I have a Person datatype. Intuitively I want it to look like this: public class Person { ...
12
votes
3answers
3k views

Working through the single responsibility principle (SRP) in Python when calls are expensive

Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and ...
3
votes
5answers
455 views

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 { ...
0
votes
1answer
148 views

Is a Factory calling a Factory an anti-pattern or an extension of the Single Responsibility Principle?

I'm busy playing around with some training material to help teach some of the juniors the factory pattern. Whilst writing the example, I can't help but think this might be an anti-pattern. Lets say ...
40
votes
10answers
6k views

Applicability of Single Responsibility Principle

I recently came by a seemingly trivial architectural problem. I had a simple repository in my code that was called like this (code is in C#): var user = /* create user somehow */; _userRepository.Add(...
2
votes
1answer
151 views

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like: login (UserAuthenticateModel) Handle user sessions: user login tokens, fetching user from session if set in session, ect' (UserSessionsModel) ...
-1
votes
3answers
271 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
1
vote
3answers
249 views

Responsibility of a Factory

I am trying to refactor a huge chunk of our software, and it requires to set up a factory. However, I am not sure where lies its responsibility. (PS: The code below is shown simply as an illustration ...
2
votes
3answers
510 views

Confusion on Single Responsibility Principle (SRP) with modem example?

I am currently reading through Robert Martins book "Agile Software Development" book and I am struggling to see how his modem example provides any benefit. He says that he has an interface that ...
4
votes
1answer
178 views

Should I comply with SRP when designing relational tables?

As far as I know, the single responsibility principle concerns functions, classes and modules. Now I am designing a database and I wonder if this principle should be applied to relational tables. ...
0
votes
3answers
241 views

Should a method decide whether to execute or not? [closed]

I couldn't find a question on SE but it has probably been asked elsewhere already (in case, please mark it). A method containing code to run just with specific external conditions can: decide ...
1
vote
0answers
317 views

Designing a multithreaded TCP/UDP server for audio sharing

As briefly introduced in the question title, I am trying to design and implement a server application able to let clients share audio contents between themselves. In order to achieve that, I decided ...
3
votes
2answers
370 views

How to use single responsibility with functions when I need to reuse procedures?

I've just read the book called Clean Code. The author (Robert C. Martin) talks about a single responsibility that a function should have in a program. It should only do one thing. Now, I would like ...
3
votes
2answers
266 views

Does method argument self-sanity checking violate the SRP?

I have a method login() which essentially sends a login request to a remote server. As I do not want to waste server resources on processing invalid data, I decided to consider sanity checking the ...
2
votes
2answers
210 views

Single responsibility principle - importer

I'm writing an importer, it should fetch some data from the database and put that data into appropriate places. Now the question is, should the importer itself fetch that data, or should that data(to ...
1
vote
2answers
99 views

Apply Single Responsibility Refactoring in Form App

I really don't understand the SRP applied to a "real" project (really not so real but can help me to know your approach) I find very difficult to divide and assign responsibility to my classes. So I ...
9
votes
7answers
2k views

Separation of concerns: When is it “too much” separation?

I really love clean code and I always want to code my code in the best possible way. But there was always one thing, I didn't really understand: When is it too much of "separation of concerns" ...
1
vote
1answer
701 views

Entity Framework - extending OR injecting services into DB Context

I fear I'm asking a somewhat silly question, but I'm now completely lost as to which principle I should follow. To my understanding - in terms of Single Responsibility Principle it's best we don't ...
8
votes
3answers
3k views

Designing a REST API with resource relationships?

I'm working to design a REST API to be consumed by a React SPA. The client-side of the SPA queries data about a relationship between two entities: Team and Player where Teams have many Players and ...
2
votes
3answers
229 views

Does SRP feed tight coupling?

I designed a function which, afterwards, I noticed it is clearly doing 2 very different tasks in the same time. So now I am thinking to split it into 2 different functions, each one of them doing ...
2
votes
1answer
99 views

Refactoring of a client calling a Rest Service

I have a class that is responsible for calling a service and returning a response. The contract is like this interface ServiceClient { ServiceResponse process(ServiceSubmissionParams params); } ...
4
votes
2answers
229 views

Is it violation of single responsibilty to add a method to an existing API

Say i have a Rest API that has a POST and GET method. If i want to overwrite a resource in the API i can call the GET method to get the original item and then call the POST method to replace that ...
3
votes
4answers
499 views

Is Abstracting your code too much a bad use of SOLID Principles?

After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come ...
-1
votes
2answers
134 views

How to choose the most suitable solution for a problem given some choices?

To ilustrate my main concern let's start by considering a "trivial" typical problem, data filtering & parsing coming from a process and dumping the information onto something {gui console, file, ...

1
2 3 4 5