Questions tagged [solid]

Mnemonics for set of design principles: Single responsibility, Open-closed, Liskov substitution, Interface segregation, Dependency inversion

In object-oriented computer programming, the term SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable. The principles are a subset of many principles promoted by Robert C. Martin. Though they apply to any object-oriented design, the SOLID principles can also form a core philosophy for methodologies such as agile development or adaptive software development. The theory of SOLID principles was introduced by Martin in his 2000 paper Design Principles and Design Patterns, although the SOLID acronym itself was introduced later by Michael Feathers.

Concepts

Single responsibility principle

a class should have only a single responsibility (i.e. changes to only one part of the software's specification should be able to affect the specification of the class).

Open/closed principle

"software entities … should be open for extension, but closed for modification."

Liskov substitution principle

"objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program." See also design by contract.

Interface segregation principle

"many client-specific interfaces are better than one general-purpose interface."

Dependency inversion principle

one should "depend upon abstractions, [not] concretions."


More to read: SOLID

393 questions
3
votes
1 answer

How does this example from Robert Martin's book violate the Single Responsibility Principle?

According to the book "Clean Code" on page 38, the following lines of code violate the single responsibility principle. However, I cannot understand how there are "multiple" reasons for it to change? public Money CalculatePay(Employee e) throws…
fibono
  • 139
1
vote
1 answer

Counterpart to Single Responsibility Principle: minimizing number of places to touch

Uncle Bob Martin frames the Single Responsibility Principle as "A class should have only one reason to change." I wonder, is there any name for a converse principle like: "a single reason to change should impact only one class"? In other words,…
wrschneider
  • 1,329
1
vote
1 answer

Dependency Inversion Principle

I have been studying also S.O.L.I.D. and watched this video: https://www.youtube.com/watch?v=huEEkx5P5Hs 01:45:30 into the video he talks about the Dependency Inversion Principle and I am scratching my head? I had to simplify it (if possible) to…
0
votes
2 answers

By applying the ISP are we bound to segregating the class too?

So basically the ISP states we should break big interfaces with members that are not cohesive with each other to smaller and more cohesive interfaces, which is very close (if not the same) to what is stated in the SRP. Assume we have a Printer class…
0
votes
1 answer

Does my example violate LSP?

Consider this example: public class SimpleValidator { public virtual bool InRange(int x) { return x >= 6 && x <=12; } } public class OffsetAwareValidator : SimpleValidator { int offset = 0; public…
-1
votes
2 answers

Is this a good example of using the Dependency Inversion Principle?

So I have a high level module, that uses a low level module (I intend to use this example for language agnostic explanatory purposes, so I removed access modifiers, getters & setters etc.): Class SalariesHandler { // properties… Printer…
Oren A
  • 270