Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
3 votes
2 answers
271 views

Invariant rule in Liskov Substitution Principle

From Liskov Substitution Principle, I am still not very clear about the invariant rule. I read through many posts but I still have doubts. My example is picked from this blog, the example is slightly ...
Rahul Chakrabarty's user avatar
3 votes
4 answers
209 views

Does interface segregation principle apply to configuration data holders?

If you have a class representing your applicative config file. Instead of injecting that config class everywhere, would it be good application of interface segregation principle to expose several ...
Calimero's user avatar
2 votes
2 answers
2k views

Is this design too convoluted?

I'm trying to experiment with SOLID in order to get a better grasp of its' concepts. With that in mind, I'm making a card game project. There's a GameUtils project that contains the following classes:...
CBredlow's user avatar
  • 131
-1 votes
1 answer
136 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 ...
Tizio Fittizio's user avatar
0 votes
2 answers
197 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 ...
Boudebouz1's user avatar
2 votes
5 answers
411 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 ...
ScottishTapWater's user avatar
2 votes
3 answers
231 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 ...
amarsha4's user avatar
  • 176
1 vote
3 answers
81 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(...
Velocoder's user avatar
  • 129
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 ...
bugger's user avatar
  • 79
2 votes
2 answers
330 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 ...
wcminipgasker2023's user avatar
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 ...
Derek Allums's user avatar
2 votes
1 answer
1k 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 ...
Rafael Alencar's user avatar
1 vote
2 answers
221 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 ...
Tizio Fittizio's user avatar
1 vote
4 answers
382 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 ...
Ash's user avatar
  • 219
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 ...
Michael Moreno's user avatar
4 votes
1 answer
230 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 ...
Chewers Jingoist's user avatar
-2 votes
1 answer
100 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 "...
tail's user avatar
  • 101
5 votes
4 answers
463 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 ...
Kevin Greetham's user avatar
-1 votes
2 answers
211 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 ...
Shahbaz Khan's user avatar
2 votes
1 answer
262 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 ...
Antonio Gamiz Delgado's user avatar
2 votes
2 answers
244 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 ...
Dennis's user avatar
  • 8,247
0 votes
1 answer
409 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 ...
user16405900's user avatar
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 ...
Stefan Rendevski's user avatar
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 ...
underthevoid's user avatar
-1 votes
1 answer
387 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 ...
Martin's user avatar
  • 1
0 votes
1 answer
1k 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, ...
Andrew Stephens's user avatar
8 votes
6 answers
440 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. ...
hamid_c's user avatar
  • 197
2 votes
3 answers
395 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 ...
bridgemnc's user avatar
  • 241
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 ...
Alexis Winters's user avatar
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 ...
Eric Gumba's user avatar
1 vote
0 answers
151 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 ...
David's user avatar
  • 21
0 votes
3 answers
144 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 ...
mtulun's user avatar
  • 13
3 votes
6 answers
787 views

Liskov Substitution Principle Inconsistency? How to figure out?

Liskov Substitution Principle states: "if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program (...
Rodrigo Branas's user avatar
1 vote
2 answers
98 views

How to improve the design of the code using tools (e.g. git)?

There is a bunch of books that state principles about good code (SOLID, DRY, Design patterns etc.) Those principles are solutions to some problems. An application of those principles could go like ...
SomeThoughts's user avatar
0 votes
1 answer
211 views

Why doesn't Laravel actively support Service Classes?

There must be a good reason for this. Laravel's default pattern makes no use of Service Classes... but the Laravel community's best practices is for business logic to be stored in them. Laravel's ...
Django Reinhardt's user avatar
1 vote
1 answer
234 views

Wrapping methods without Decorator Pattern or AOP

I have a Dao interface which doesn't have any methods defined. Then I have multiple classes which implement this interface, like PetDao and HouseDao. For some of the implementation classes, and some ...
Pepit's user avatar
  • 13
-1 votes
2 answers
124 views

How should I implement this requirement following SOLID?

Assume we had a User class which should hold references for all different kinds of request, let's say at the moment we only have 2 :RequestA and RequestB, both inherit from the base class Request. Now ...
underthevoid's user avatar
0 votes
2 answers
108 views

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 ...
underthevoid's user avatar
1 vote
4 answers
220 views

When should a method depend on a data source and NOT have it declared as a parameter?

I was assigned a code review to one of my colleagues. I posed the following, which I wanted to share here in order to hear whether I am right or wrong. Consider the following code snippet: public void ...
Veverke's user avatar
  • 451
0 votes
2 answers
203 views

Should we put behaviors (method) in constant class in Java?

Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final ...
Pulkit Gupta's user avatar
2 votes
2 answers
474 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; ... ...
Cosmica's user avatar
  • 87
1 vote
1 answer
121 views

Any workarounds to split functionality from the class?

Hello everyone)) I am working on the react application, where mobx is being used for the state management. Some time ago I have added such class: class EventLogStore { private _eventLogRecord: ...
Nikita's user avatar
  • 157
2 votes
3 answers
316 views

When does a function violate the SRP?

I have a function that was written because several methods used the same sequence of code so an abstraction was useful. The function takes a string representing the path to a registry key and then a ...
pstatix's user avatar
  • 1,047
1 vote
1 answer
401 views

Clean Architecture: Controller creates a RequestModel instance or implements RequestModel?

I have checked many articles and discussions around the web. So we have the main diagram: So we have Controller pointing directly to RequestModel. So straight to the point, should I: Create a ...
Christian H's user avatar
2 votes
1 answer
562 views

Serialization and SOLID principles

I have several configuration structures that can be JSON serialized and deserialized as follows: namespace config { struct Foo { std::string hostname {}; std::string ip_address{}; ...
NutCracker's user avatar
1 vote
1 answer
127 views

OOP Design - Null Object Pattern or design pattern

Consider the code snippet public interface Car { string getColor(); void Drive(); } public class CarWithAutomaticTransition : Car { public string getColor() { return "Red"; } ...
cowboydan's user avatar
  • 221
2 votes
2 answers
346 views

What does abstraction mean in Bridge design pattern?

The bridge pattern is defined as 'The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently'. I get that abstraction here doesn't mean abstract class /...
takasugi's user avatar
  • 293
4 votes
2 answers
139 views

How do I trigger conditional post processing action without violating SRP?

I have a User Model as below, this Model class is in the shared library. class User { private long userId; private String email; private String userType; private long departmentId; ...
Govinda Sakhare's user avatar
2 votes
1 answer
127 views

How do refactor a code which picks service based on null checks on field?

I have a bean that has around 10+ fields and it may grow till 30 odd fields. The bean is a contract between applications to share data over an HTTP call. Basically, a downstream application will set ...
Govinda Sakhare's user avatar
2 votes
2 answers
760 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 ...
ThePorcius's user avatar

1
2 3 4 5
8