Questions tagged [solid]

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

Filter by
Sorted by
Tagged with
2 votes
2 answers
449 views

Exposing methods for polymorphic children from the aggregate root

Consider the following fictitious toy example: There is an aggregate root DayChecklist that holds a list of Tasks planned for the day: class DayChecklist { String id; DateTime today; ... ...
-1 votes
1 answer
128 views

Will I lose confidence of my code working in mocking dependency injected services? [duplicate]

Let's say that I have a class with a service that is going to be injected at runtime: class Thing { private magic: IMagic; // Magically injected service public doStuff(){ // Do a lot ...
0 votes
1 answer
131 views

Possible violation of LSP when adhering to ISP?

Recently I read about ISP and wanted to implement it into my project. While implementing my design I think I found a flaw which violates LSP but I'm not sure. Given I have a game project, in which ...
2 votes
5 answers
389 views

What exactly is the single responsibility principle? [duplicate]

I've generally understood the SRP to roughly mean: Each class should do one thing Exactly what "one thing" is is up for debate. However, I've recently seen claims that the entire SRP has ...
2 votes
3 answers
225 views

How to retain the concrete type when writing base-class-oriented code?

A scenario often arises when attempting to make some existing code reusable. I introduce an interface to represent the commonality between some new feature I'm implementing and some existing ...
16 votes
4 answers
12k views

“Depend on abstractions, not on concretions” what is the exact meaning of this term

I was reading SOLID principles on a website, in which for D - Dependency Inversion Principle it says: “Depend on abstractions, not on concretions” In other words. we should design our software in ...
1 vote
3 answers
75 views

Refactoring Controllers publishing different events with MediatR library

I have Controller that basically publishes different Event based on some input criteria, simplified version of the logic is here: [HttpPost] public async Task<ActionResult> Create(...
6 votes
2 answers
2k views

How to implement many-to-many relationships without violating design principles in OOP?

I have an event class that holds details of a volunteering "Event" class. There is an "EXCO" Class that can create and edit details of said Events. There is also a "Volunteer ...
2 votes
2 answers
305 views

In "Liskov Substitution Principle", are "Preconditions can't be strengthened in a subtype" & "Postconditions can't be weakened in a subtype" the same?

According to Is this a violation of the Liskov Substitution Principle?, as I understand, the top answer currently says the code below is violating "Liskov Substitution Principle": public ...
13 votes
4 answers
5k views

Do Interactors in "clean architecture" violate the Single Responsibility Principle?

The SRP states that a class (module) should have only one reason to change. The "duties" of an Interactor in Bob Martin's clean architecture are, per use case: receive requests/inputs from a ...
70 votes
8 answers
15k views

When to *not* use SOLID principles

Coming from a math background, counterexamples are equally, if not more, helpful to me for understanding concepts than examples. I've seen many, many examples of when and how to use the SOLID ...
2 votes
1 answer
925 views

Clean architecture - how to manage use cases that depends on external apis

How to apply clean architecture concepts in a software that depends on External APIs. Example: A business that offers some kind of subscription to its users. Its convinient to store some subscription ...
13 votes
3 answers
3k views

Applying SOLID principles

I am quite new to the S.O.L.I.D. design principles. I understand their cause and benefits, but yet i fail to apply them to a smaller project which I want to refactor as a practical exercise to use the ...
1 vote
2 answers
218 views

Where to determine different behaviour for a child class with feature flags

Let's say that I have a Parent class and a Child class, Parent relies on Child to perform, say, some network request: class Parent { ... public init(){ const child = new Child(); const ...
1 vote
4 answers
377 views

Is there any intent behind SRP other than SoC

Edit based on responses so far I am starting with an edit so as to save future contributors from going down the same path others have. I am only interested in contributions that stick to the exact ...
60 votes
5 answers
35k views

What are the design principles that promote testable code? (designing testable code vs driving design through tests)

Most of the projects that I work on consider development and unit testing in isolation which makes writing unit tests at a later instance a nightmare. My objective is to keep testing in mind during ...
46 votes
3 answers
34k views

Programming SOLID Principles

Over time I could understand two parts of SOLID – the “S” and “O”. “O” – I learned Open Closed Principle with the help of Inheritance and Strategy Pattern. “S” – I learned Single Responsibility ...
1 vote
1 answer
71 views

Querying objects in a list by class type vs string identifier - Best practices

I have a class Character who has a list of Spell objects that he can cast. abstract class Spell { name: string manaCost: number abstract cast() { ... } } class InvisibilitySpell extends ...
4 votes
1 answer
200 views

What is the anti-pattern for modules that group objects of the same type? [closed]

In MVC, I often seen all models in a models.py module, all views in a views.py module, and the controller - you guessed it - in a controller.py module. In other projects, I sometimes see all exception ...
52 votes
8 answers
13k views

When NOT to apply the Dependency Inversion Principle?

I am currently trying to figure out SOLID. So the Dependency Inversion Principle means that any two classes should communicate via interfaces, not directly. Example: If class A has a method, that ...
2 votes
2 answers
943 views

Should a UnitOfWork contain every Repository?

I'm trying to get the Repository/UnitOfWork pattern figured out. We're working on a project with EntityFramework and our DBContext contains 200+ tables. Right now our approach is to inject whatever ...
152 votes
12 answers
27k views

Is this a violation of the Liskov Substitution Principle?

Say we have a list of Task entities, and a ProjectTask sub type. Tasks can be closed at any time, except ProjectTasks which cannot be closed once they have a status of Started. The UI should ensure ...
-2 votes
1 answer
98 views

Does my class violate the Single-Responsibility Principle? [duplicate]

Goal: I am learning about SOLID principles and trying to refactor Gilded Rose code, in order to make it fresh and clean. What I have done: I have created an AbstractItem class as follows, which "...
5 votes
4 answers
412 views

Does my outer class adhere to the Single Responsibility Principle?

I often write front end apps with a generic MVC pattern. I use javascript but this questions is language independent and relates to OOP as a whole. I struggle to understand the SRP principle and I ...
2 votes
2 answers
723 views

The most popular definition for LSP seems very contradictory

Out of the 5 SOLID principles, I find LSP to be the most confusing one. The most popular description of this principle is simply "A subclass must be replaceable with it's base class without ...
-1 votes
2 answers
206 views

Liskov Substitution Principle Edge Case

I thought I understood Liskov Substitution Principle but then I thought of a case and I wanted to ask the community here if I get it right. So I read somewhere to check if we have violated Liskov or ...
82 votes
8 answers
18k views

How can a class have multiple methods without breaking the single responsibility principle

The Single responsibility principle is defined on wikipedia as The single responsibility principle is a computer programming principle that states that every module, class, or function should have ...
7 votes
4 answers
2k views

Clean, Modular Code vs MV* Frameworks [closed]

I've been hearing a lot about the "new" MV* frameworks. I've tinkered with KnockoutJS (I created an invoicing application), but I much prefer to write clean, modular code in raw JavaScript - ...
2 votes
1 answer
257 views

Interface segregation principle

Let's say we have the following business requirements: We have a list of dishes. They have a name and a list of ingredients. The restaurant owner always wants to have a dish (and only one) marked as ...
2 votes
2 answers
236 views

To maintain SOLID, should data preparation, conversion, and pre-computation for purposes of saving an object, be separate from data persistence layer?

I am facing a common situation where I am saving some values into database from a business object. I am using a relational database and usually I only need to save a few items that are part of the ...
2 votes
5 answers
412 views

Should methods always be closed for modification?

Say I have a method called 'functionA' that is called by a service and carries out a single piece of functionality, it is easy to unit test as it is does one thing only. If a few months later an new ...
0 votes
1 answer
348 views

Best way to name derived classes when extending its functionality [closed]

I have just recently joined a new company and one of the classes used to log information has not been written properly. So I have been asked to add new functionality to the logger. Rather than ...
8 votes
6 answers
5k views

What is more important? SOLID or KISS?

What is more important? SOLID or KISS? To be consistent with SOLID I would have to inject Decorator and Footer classes and create interfaces for them. public class HelloService { String name; ...
10 votes
4 answers
3k views

Why not apply Interface Segregation Principle to "extreme"

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
9 votes
4 answers
2k views

UnsupportedOperationException vs Interface Segregation

This is a follow up/related question to a previous question I asked regarding Interface Segregation. I'll build up on the same example, providing a bit more context. In the game I'm developing, a card ...
3 votes
3 answers
708 views

Command Query Separation. How to handle error handling for mutating functions returning void

I am learning about SOLID principles in a Pluralsight course where Command Query Separation is being discussed. I am fine with the query functions returning something (and crucially being non-mutating)...
10 votes
3 answers
3k views

Why is having bloated interfaces an anti pattern?

[I'm using the term interface here with C#'s interface in mind. I won't tag the question with a C# tag because it really isn't a C# question.] In my work we do unit and integration tests but we don't ...
-1 votes
1 answer
378 views

State machine using SOLID principles. Connecting to real devices

I am trying to implement code for switching states of a couple laboratory devices. My considerations are: how should I link the state objects, state machine object and device manager object to follow ...
0 votes
1 answer
944 views

Clean code and SOLID principles in WPF/MVVM view models?

I'm currently reading "Clean Code" by Robert Martin (which I should have read years ago), and it's given me a bit of a wakeup call, especially regarding keeping methods and classes small, ...
5 votes
4 answers
1k views

How do you do SOLID with Data Oriented Design?

As far as I know Data Oriented Design differs a lot with OOP. It encourages reusability of data, discourages polymorphism, etc. And because SOLID uses OOP a lot (especially Interface Segregation ...
18 votes
5 answers
4k views

What is the meaning of "inversion" in Dependency Inversion design principle?

I'm reading about design patterns. I know what this principle does. High-level and low-level classes depend on abstractions. But why we say this is inversion?
8 votes
6 answers
436 views

Can Data Abstraction Violate the Interface Segregation Principle?

I'm reading Clean Code In Chapter 6, Objects and data structure First talk about Data Abstraction: Hiding implementation is not just a matter of putting a layer of functions between the variables. ...
2 votes
3 answers
376 views

Is there any redundancy within the scope of SOLID principles?

I have read in an article DIP in the Wild that "When Robert Martin first discussed the DIP, he equated it a first-class combination of the Open Closed Principle and the Liskov Substitution ...
6 votes
1 answer
3k views

What are the examples of breaking Liskov Substitution Principle?

I'm aware that there are 4 ways to violate Liskov Substitution from here. But I'm not sure what these violations would like in practice. Can you show examples of code that breaks the principle for ...
17 votes
4 answers
6k views

Two contradicting definitions of Interface Segregation Principle – which one is correct?

When reading articles on ISP, there seem to be two contradicting definitions of ISP: According to first definition ( see 1, 2, 3), ISP states that classes implementing the interface shouldn't be ...
14 votes
5 answers
4k views

What would be an example of the Liskov Substitution Principle, if you don't use inheritance?

I am reading about the SOLID principles, but it seems like the Liskov-Substitution Principle primarily refers to programs that use inheritance. From my understanding people are shifting more towards ...
15 votes
1 answer
3k views

How to verify the Liskov substitution principle in an inheritance hierarchy?

Inspired by this answer: Liskov Substitution Principle requires that Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants of ...
1 vote
0 answers
147 views

How to measure LSP from SOLID Design Principles using NMI, NME and NMO

I do understand the SOLID Principles and LSP, but I want to be able to meausure how well a class diagram obeys to the LSP. Therefor I have found the "Value of LSP" metric, here is a guide ...
0 votes
3 answers
137 views

What should be the optimal management of end user messages in N-tier architecture?

I'm curious about your thoughts on this subject that we have discussed with the people around me. Especially at the architectural stage, in which layer is the most optimal and efficient way to use the ...
32 votes
6 answers
8k views

Additional line in block vs additional parameter in Clean Code

Context In Clean Code, page 35, it says This implies that the blocks within if statements, else statements, while statements, and so on should be one line long. Probably that line should be a ...

1
2 3 4 5
8