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
19
votes
9 answers

Using the Single Responsibility Principle in the "real world"

I basically want to get an idea of the percentage of people who think it's reasonable to use the Single Responsibility Principle in real-world code and how many actually do. In Podcast #38 Joel talks about how useless this OOP principle is the real…
Thiru
  • 271
  • 2
  • 11
19
votes
5 answers

What is difference between the Open/Closed Principle and the Dependency Inversion Principle?

The DIP states: High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. And the OCP states: Software entities…
18
votes
2 answers

Developing a Swift iOS app "The Right Way"

Recently, I've learned Swift and the basics to develop an iOS app. Now, I want to develop a real application by my own, but I'm very concerned about writing good code, so I've looked up for "best practices", "design patterns" and "the right way" to…
barbarity
  • 2,420
  • 1
  • 21
  • 29
18
votes
9 answers

Refactoring if-else if - else

I have the following code example if(object.Time > 0 && <= 499) { rate = .75m } else if(object.Time >= 500 && <= 999) { rate = .85m } else if(object.Time >= 1000) { rate = 1.00m } else { rate = 0m; } My question is what design…
Alex
  • 2,114
  • 9
  • 25
  • 34
17
votes
4 answers

SOLID principles implementation for C

I know SOLID principles were written for object oriented languages. I found in the book: "Test driven development for embedded C" by Robert Martin, the following sentence in the last chapter of the book: "Applying the Open-Closed Principle and the…
Oscar Castiblanco
  • 1,626
  • 14
  • 31
17
votes
3 answers

Should factories set model properties?

As part of an overall S.O.L.I.D. programming effort I created a factory interface & an abstract factory within a base framework API. People are already starting to overload the factories Create method. The problem is people are overloading the…
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137
17
votes
7 answers

S.O.L.I.D principles and compilation?

For example , regarding Single Responsibility principle : Let's talk about a Radio class : One could argue that the Radio class has two responsibilities, being volume and station management. These operations will be called from completely…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
16
votes
0 answers

What would be the most powerful argument for writing SOLID applications?

Recently I did a presentation on Dependency Injection and IoC (Inversion of Control) containers. I also was talking about SOLID principles. I think without SOLID, DI Containers make no sense. I was focusing on few arguments. Maintainability …
Dorin
  • 524
  • 3
  • 12
15
votes
2 answers

Can Interface Segregation Principle be applied to Python objects?

In an effort to apply SOLID principles to a Python project that has grown organically and is in need of re-factoring, I am trying to understand how the Interface Segregation Principle can be applied to the Python language, when Interfaces don't…
15
votes
6 answers

Avoiding If Else conditions

I want to refactor the following code to avoid if...else so that I don't have to change the method every time a new survey type comes in (Open/closed principle). Following is the piece of code I am considering to refactor: if (surveyType ==…
fahmi
  • 591
  • 6
  • 27
15
votes
4 answers

Understanding the practical benefits of using the Single Responsibility Principle

I'm trying to understand the SRP but, whilst I understand the reasoning behind how to apply it, I'm not really seeing the benefit of doing so. Consider this example, taken from Robert Martin's SRP PDF: interface IModem { void Dial(string…
John H
  • 14,422
  • 4
  • 41
  • 74
15
votes
6 answers

How to comply with Liskov's Substitution Principle (LSP) and still benefit from polymorphism?

The LSP says "The derived types must not change the behavior of the base types", in other words "Derived types must be completely replaceable for their base types." This means that if we define virtual methods in our base classes, we have violated…
The Light
  • 26,341
  • 62
  • 176
  • 258
15
votes
3 answers

Does implementing multiple interfaces violate Single Responsibility Principle?

From Wikipedia: Single responsibility principle states that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. Does that mean implementing multiple interfaces violates this…
14
votes
1 answer

What is a Refused Bequest?

Could someone please explain what does Refused Bequest means? I tried reading some articles and says its a kind of code smell or in wiki it tells that it is a class that overrides a method of a base class in such a way that the contract of the base…
14
votes
6 answers

A very common C# pattern that breaks a very fundamental OOP principle

Here is a very simple question, which I'm still very uneasy about: Why is it widely accepted now for a class to return a reference to its private member through an accessor method? Doesn't this totally break the encapsulation principle? If this is…
samus
  • 6,102
  • 6
  • 31
  • 69