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
0 answers

Exporting EF Entity to Excel/PDF and How to Exclude Attributes without violating SRP?

I am working with Entity Framework as my ORM for a project at work, and I need to be able to write only some of the values of each entity to an existing Excel template. The data is required to be formatted as Excel Tables so that the end user can…
0
votes
1 answer

Proper Class Construction: Using Multiple Hard Dependencies

I'm trying to integrate Single Responsibility Principle into my Java code by refactoring large classes (2000+ lines) into smaller, cohesive classes (~200 lines). However I'm confused how to properly reduce coupling between classes, since certain…
0
votes
1 answer

Wierd interface method for point Iterator

I have to iterate over specific points of perimeter rectangle (in some cases I need to iterate over one line of this rectangle, In other cases I need to iterate over entire rectangle). I have an interface PointIterator. struct Point { double…
Vladimir Yanakiev
  • 1,240
  • 1
  • 16
  • 25
0
votes
1 answer

Open / Closed Principle & Single Responsibilty -- Graphs

I am coding a Graph exploration program and have hit a bit of a stumbling block. My graph is made up of Vertex and NetworkLink objects, and can be obatined by querying a GeographyModel object. The idea is List is retrieved from the…
0
votes
1 answer

OOD - Is SRP context dependent?

This is more of an OOD problem and I have no specific code to post here. Can the same class violate the SRP in one context and be SRP compliant in other without changing a single line of a code? In other words, can there be a situation that within…
x86-Debug
  • 65
  • 4
0
votes
1 answer

Interface Segregation Framework and Pattern

I am writing an app that processes a bunch of ticker data from a page. The main class that I am working with is called Instrument, which is used to store all the relevant data pertaining to any instrument. The data is downloaded from a website, and…
user3745593
  • 41
  • 1
  • 1
  • 4
0
votes
1 answer

Single Responsibility Principle Violating

I have a class with two methods. While app running I send instance of Operations to another class as a parameter. public class Operations { /// /// calculating the available money to use in operations /// void…
Tuncaf
  • 231
  • 2
  • 13
0
votes
1 answer

When using SOC & SRP should I be concerned about too much parameter passing between code blocks?

How far do I break down individual tasks within a typical scenario of "Web application reacts to user input"? For example, in the case below, say a scenario is "User submits a form, causing user data to be turned into an Object (technical detail)…
0
votes
2 answers

Single responsibility principle - function

I'm reading some tuts about SOLID programming, and I'm trying to refactor my test project to implement some of those rules. Often I have doubts with SingleResponsibilityPrinciple, so I hope someone could help me with that. As I understood, SRP means…
Ned
  • 3,961
  • 8
  • 31
  • 49
0
votes
1 answer

UICollectionViewDataSource methods are not getting called when data-source is a separate class

I created a UICollectionView inside a UITableViewCell and a separate data-source class DataSource for this collection-view. DataSource conforms to the UICollectionViewDataSource protocol and I have also assigned the dataSource of an instance of…
enigma
  • 865
  • 9
  • 22
0
votes
1 answer

Does dependency injection by smart pointers violate Single Responsibility Principle?

My concern is that when using either shared_ptr or unique_ptr I stick to one ownership model - either injected objects is shared or my own. And I think this is is secondary class responsibility - to care of injected objects lifetime. So, does it…
0
votes
0 answers

Single responsibility principle and building a tree of objects

Let a class Rel denotes a kind of SQL relationship between two tables (that is Rel may be HasA or HasMany, etc.) Will it contradict single responsibility principle ("class or module should have one, and only one, reason to change") if instance…
porton
  • 5,214
  • 11
  • 47
  • 95
0
votes
1 answer

Does the DbFunctions class violate SRP

In the System.Data.Entity namespace there's the DbFunctions class. It has nearly 100 functions that handle string manipulation, DateTime calculations, and statistical functions. There are a lot of SRP questions on SO, so feel this is the…
Big Daddy
  • 5,160
  • 5
  • 46
  • 76
0
votes
1 answer

Rails Presenter - Interacting with 2 different models that share the same attribute

I have 2 models in a large Rails app room and inquiry. They both share an attribute/column cancellation_policy. At the point at the point at which an inquiry (alias: booking) is made the cancellation_policy is copied from the…
0
votes
2 answers

SRP, DI and app.config: when to instantiate injecting classes?

I'm refactoring a small report-generating application and making it adhere to the SOLID principles, etc. So, all my classes follow SRP with DI and I use app.config for most parameter variations. I'm not using any DI frameworks, yet, but rather…