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
25
votes
6 answers

How do you determine how coarse or fine-grained a 'responsibility' should be when using the single responsibility principle?

In the SRP, a 'responsibility' is usually described as 'a reason to change', so that each class (or object?) should have only one reason someone should have to go in there and change it. But if you take this to the extreme fine-grain you could say…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
25
votes
6 answers

Aren't Information Expert & Tell Don't Ask at odds with Single Responsibility Principle?

Information-Expert, Tell-Don't-Ask, and SRP are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about. Code that favors SRP but violates Tell-Don't-Ask & Info-Expert: Customer bob = ...; //…
24
votes
4 answers

How to obey Law of Demeter?

Any time I see articles about Law of Demeter the author never seems to give a solid example of how to obey this law. They all explain what it is and show an example of breaking the law but that is easy. There is probably lots of ways to obey this…
ibanore
  • 1,500
  • 1
  • 12
  • 25
22
votes
5 answers

How to implement SOLID principles into an existing project

I apologize for the subjectiveness of this question, but I am a little stuck and I would appreciate some guidance and advice from anyone who's had to deal with this issue before: I have (what's become) a very large RESTful API project written in C#…
Ash
  • 24,276
  • 34
  • 107
  • 152
22
votes
7 answers

Clean code for removing switch condition(using polymorphism)

As SOLID principles say, it's better to remove switch conditions by converting them to classes and interfaces. I want to do it with this code: Note: This code is not real code and I just put my idea into it. MessageModel message =…
Siamak Ferdos
  • 3,181
  • 5
  • 29
  • 56
22
votes
4 answers

How to use dependency injection with inheritance in C#

Introduction Hi everyone, I'm currently working on a persistence library in C#. In that library, I have implemented the repository pattern where I'm facing a SOLID issue. Here is a simplified example my current implementation to focus on the…
Maxime Gélinas
  • 2,202
  • 2
  • 18
  • 35
22
votes
9 answers

Design pattern for default implementation with empty methods

Is there a specific design pattern that describes the scenario where a non-abstract default implementation is provided that implements all or some of the methods on the interface with empty, NO-OP implementations. This being done with the intent of…
21
votes
4 answers

DDD: What kinds of behavior should I put on a domain entity?

My team tries very hard to stick to Domain Driven Design as an architectural strategy. But, most of the time, our domain entities are pretty anemic. We'd like to be putting more business/domain behavior on our domain entities. For example, Active…
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
21
votes
5 answers

How to practice SOLID principle of OOP design?

I'm new to SOLID principle but I understand it. My main problem is having a hard time designing my classes to follow the SOLID specially the Dependency Inversion. Sometimes it's easy to write the whole logic into procedural pattern rather than to…
Ruby
  • 285
  • 1
  • 3
  • 8
21
votes
4 answers

Is "high cohesion" a synonym for the "Single Responsibility Principle?"

Is high cohesion a synonym for the Single Responsibility Principle? If not, how are they different?
20
votes
3 answers

How can Hilt be used effectively in multi-module apps following CLEAN architecture principles?

I am building an Android app following the Clean Architecture Principles. Here is what I've got: app module: Contains all the Android dependencies. Uses MVVM with ViewModel from the arch components. ViewModels only communicate with UseCases, which…
20
votes
5 answers

Open source projects that demonstrate TDD and SOLID priciples

I asked a similar question before, and got some good answers, but I think it was too general. Examples of great software design and implementation Does anyone know of any open-source projects that demonstrate really good TDD practices, and SOLID…
Andy White
  • 86,444
  • 48
  • 176
  • 211
20
votes
8 answers

Examples of great software design and implementation

I hope this isn't a duplicate... What is the most solidly designed and implemented software system/framework/application that you've come across? It seems like TDD, SOLID principles, OO design patterns, and things like that can be easily theorized…
Andy White
  • 86,444
  • 48
  • 176
  • 211
20
votes
6 answers

Are there any rules for OOP?

Recently I heard that there are 9 rules for OOP(Java). I know only four as Abstraction, Polymorphism, Inheritance and Encapsulation. Are there any more rules for OOP?
Viki
  • 251
  • 1
  • 4
  • 7
20
votes
6 answers

Does Repository Pattern follow SOLID principles?

I am doing some research on SOLID principal, and found some issues in implementations of Repository pattern. I am going to explain each and every problem, Please correct me if I am wrong. Problem 1 Repository Pattern Breaks Single responsibility…
Ankit Sarkar
  • 547
  • 1
  • 6
  • 20
1 2
3
76 77