Questions tagged [single-responsibility-principle]

For questions about the Single Responsibility Principle in object-oriented programming, one of the SOLID principles coined by Robert C. Martin. It states that a module should have only one reason to change.

Robert Martin was inspired by David Parnas, Edsger Dijkstra (who coined the term Separation of Concerns) and Larry Constantine (who coined the terms Coupling and Cohesion). During the late 1990s, Martin consolidated their ideas into the Single Responsibility Principle.

Martin's definition of the SRP evolved to become,

Gather together the things that change for the same reasons. Separate those things that change for different reasons.

In keeping with the previous authors who inspired him, Martin notes that,

...this is just another way to define cohesion and coupling.

In contrast with the principle, the SRP is focused on people rather than functionality.

As you think about this principle, remember that the reasons for change are people. It is people who request changes. And you don’t want to confuse those people, or yourself, by mixing together the code that many different people care about for different reasons.

The SRP later became the first of Martin's .

445 questions
0
votes
1 answer

shared library under ubuntu

i have compiled srp-2.1.2 under ubuntu using make ,it creat a file libsrp.a. can any one tell me how can i use libsrp.a as shared library?.i want to use libsrp in a c# file under ubuntu by using dllimport.please tell me what is the meaning of…
Hema Joshi
  • 247
  • 1
  • 5
  • 10
0
votes
1 answer

Is it bad to inject controller class into a controller class?

By trying to follow single responsibility principle, I decided that rendering form view I could move to another class. Also to render form I already am planning to use 5 dependencies. So the main controller which injects form will have less…
0
votes
2 answers

compiling srp-2.1.2 under ubuntu

i have download srp-2.1.2 package and just try to compile it under ubuntu. but it is not going to be compiled completely. please tell me how to compile it under ubuntu . error- root@ubuntu:~/Desktop/srp-2.1.2/libsrp# make gcc -DHAVE_CONFIG_H -I. -I.…
Hema Joshi
  • 247
  • 1
  • 5
  • 10
0
votes
1 answer

Android - Separate async http code from the activity according to SOLID principles

I want to separate async http code from the activities as I'm reusing the code. This is what I am doing currently: I want to get a list of projects form a REST API and store it in an array. (Assume I'm not using local caching as I want to load them…
0
votes
3 answers

Should component be able to validate itself

I am now struggling with a dilemma. In my system I get a lot of data from various sensors in one complicated message and not well structured message. I can't influence it's structure and it also changes quite often, so as a first step i translate it…
0
votes
1 answer

Graph limitations - Should I use Decorator?

I have a functional AdjacencyListGraph class that adheres to a defined interface GraphStructure. In order to layer limitations on this (eg. acyclic, non-null, unique vertex data etc.), I can see two possible routes, each making use of the…
0
votes
0 answers

ASP.NET MVC - Can I combine words into a route?

I have an ASP.NET MVC site that processes, say, Cars, CarParts, and non-HTTP verbs. Like this sort…
0
votes
2 answers

Single Responsibility Principle Composite Classes

I have a Entity class Public class Company { public int Id {get;set;} public string Name {get;set;} . . . public List
Addresses{get;set;} public List Domains{get;set;} } And The manager is supposed to…
0
votes
2 answers

How to create an object using Factory method, instead of supplying alternative object constructor

I am having some trouble applying Factory Pattern. I have a class that I usually call as Product($modelNumber, $wheelCount). But in a part of legacy code that I am refactoring, I do not have $modelNumber, and only have $productID, where the link…
Dennis
  • 7,907
  • 11
  • 65
  • 115
0
votes
1 answer

How to correctly handle success and errors after using another method

I am having trouble coming up with a solution to handle success or failure(errors) that is consistent throughout my whole application, so far I have been stuck deciding from 3 possible solutions.(I am relatively new to OOP) For example, if I wanted…
cecilli0n
  • 457
  • 2
  • 9
  • 20
0
votes
0 answers

Symfony2 Manager classes and Entity Repositories dependencies

I am currently refactoring bits of a medium sized project and encountered the following. (Bit of pseudo code to simplify the example) class PostRepository { } class PostManager { /** * @var PostRepository */ private…
Machiel
  • 1,495
  • 12
  • 15
0
votes
0 answers

SRP at the expense of efficiency? Or incorrect useage?

If we have 2 classes class databaseGateway class format Lets say we make a query through databaseGateway and get 5 rows. We want to apply formatting and update the row in the database. We can do all of this simply within 1 loop foreach($rows as…
cecilli0n
  • 457
  • 2
  • 9
  • 20
0
votes
2 answers

Send Email Function

I have a user controller that I use for my front-end of my Codeigniter application that handles the registration, login, forgot-password, view (profiles) pages and I am trying to decide on where the best place is for a function to go for a send…
0
votes
1 answer

CodeIgniter Models & Controllers Confusion

Today i've decided that I should start relying on a PHP framework because writing from scratch every time is really exhausting. As my framework I've chosen CodeIgniter, and I want to say It's amazing and easy to use. But I have some questions and…
0
votes
0 answers

Correct Way To Structure Classes/Methods in Codeigniter when Following the Single Responsibility Principle

I'm in the process of trying to better my approach to programming, and part of this approach is to read a recommended (and already hugely influential to me) book 'Clean Code' by Robert C Martin. In the book, it says how important it is that each…
john
  • 1,280
  • 1
  • 18
  • 48