Questions tagged [solid-principles]

SOLID is an acronym for five principles of object-oriented design introduced or documented by Robert C. Martin. Use this tag on questions regarding any of the individual principles, or their relationships to other OOD concepts. Also use the five individual tags, when applicable.

The SOLID principles are language-agnostic principles of object-oriented design. (Not to be confused with tools and conventions for decentralized social applications proposed by Tim Berners-Lee and MIT.) In a series of articles in 1996, Robert C. Martin documented the existing Open-Closed and Liskov Substitution principles, and introduced the other three. Michael Feathers invented the acronym afterwards.

The acronym stands for:

References:

1149 questions
1216
votes
35 answers

What is an example of the Liskov Substitution Principle?

I have heard that the Liskov Substitution Principle (LSP) is a fundamental principle of object oriented design. What is it and what are some examples of its use?
222
votes
16 answers

What is the dependency inversion principle and why is it important?

What is the dependency inversion principle and why is it important?
108
votes
13 answers

Difference between Single Responsibility Principle and Separation of Concerns

What is the difference between Single Responsibility Principle and Separation of Concerns?
101
votes
3 answers

Can you explain Liskov Substitution Principle with a good C# example?

Can you explain Liskov Substitution Principle (The 'L' of SOLID) with a good C# example covering all aspects of the principle in a simplified way? If it is really possible.
pencilCake
  • 51,323
  • 85
  • 226
  • 363
77
votes
1 answer

Application architecture/composition in F#

I have been doing SOLID in C# to a pretty extreme level in recent times and at some point realized I'm essentially not doing much else than composing functions nowadays. And after I recently started looking at F# again, I figured that it would…
TeaDrivenDev
  • 6,591
  • 33
  • 50
75
votes
5 answers

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

How does the SOLID "Interface Segregation Principle" differ from "Single Responsibility Principle"? The Wikipedia entry for SOLID says that ISP splits interfaces which are very large into smaller and more specific ones so that clients will only…
71
votes
6 answers

Liskov substitution principle - no overriding/virtual methods?

My understanding of the Liskov substitution principle is that some property of the base class that is true or some implemented behaviour of the base class, should be true for the derived class as well. I guess this would mean when a method is…
68
votes
10 answers

SOLID vs. YAGNI

One of the most frequent arguments I hear for not adhering to the SOLID principles in object-oriented design is YAGNI (although the arguer often doesn't call it that): "It is OK that I put both feature X and feature Y into the same class. It is so…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
63
votes
7 answers

Single Responsibility Principle vs Anemic Domain Model anti-pattern

I'm in a project that takes the Single Responsibility Principle pretty seriously. We have a lot of small classes and things are quite simple. However, we have an anemic domain model - there is no behaviour in any of our model classes, they are just…
61
votes
1 answer

Can't seem to understand SOLID principles and design patterns

I'm trying to get into OOP lately, and I'm having trouble with SOLID principles and design patterns. I see why people use them, and I really want to use them too, but I can't wrap my head around developing my classes to the specifications. I would…
will
  • 1,491
  • 1
  • 19
  • 28
60
votes
14 answers

What is the meaning and reasoning behind the Open/Closed Principle?

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design?
56
votes
3 answers

Learning Single Responsibility Principle with C#

I am trying to learn the Single Responsibility Principle (SRP) but it is being quite difficult as I am having a huge difficult to figure out when and what I should remove from one class and where I should put/organize it. I was googling around for…
Guapo
  • 3,446
  • 9
  • 36
  • 63
51
votes
2 answers

Having a repository dependent on another repository

I've recently been spending time reading up on SOLID principles and decided to seeing how the code base I work with compares. In some of our code there is a repository (repository A). When a record is to be deleted from the repository A, we also…
MrGrumpy
  • 543
  • 1
  • 4
  • 9
47
votes
7 answers

Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

I was recently having a debate about the Dependency Inversion Principle, Inversion of Control and Dependency Injection. In relation to this topic we were debating whether these principles violate one of the pillars of OOP, namely Encapsulation. My…
45
votes
4 answers

SOLID for functional programming

Coming from an OOP language, I am familiar with the SOLID principles of object oriented design. It seems like some of these would fit into a functional programming model, while other parts make no sense in a world lacking state. Is there a similar…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
1
2 3
76 77