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
0
votes
4answers
157 views

Is it an issue to have multiple almost identical interfaces?

Is it an issue to have multiple almost identical interfaces? In our company we have 9 identical interfaces for 9 document types, like: Book, Contract, Person, etc. interface IBookInner { Book ...
3
votes
3answers
214 views

Is my understanding of SOLID principles correct regarding my concrete implementation?

I read everything and its opposite about how to organize its code. Of course, I try to follow the SOLID principles, but since I consider myself quite a beginner, I would need some outside advice on ...
1
vote
1answer
128 views

Using lambdas to decouple the client code

The ISP says that the client should not depend on things what are not needed. As a solution small focusing interfaces (contracts) can be used: interface RegisterUser { User register(String username);...
11
votes
2answers
2k views

Does TDD contradict the open-closed principle?

My understanding of the TDD methodology is that (failing) test cases are written promptly after finalizing the requirements. My understanding of the open-closed principle (in the context of OOP) is to ...
-1
votes
1answer
42 views

Does adding a method to a sub-class with the same name of the parent class method, break substitutability principle?

Let T be a superclass, and S derives from it: abstract class T{ public virtual byte[] Foo(string str){...} } class S : T{ public override byte[] Foo(string str){....} public byte[] Foo(string str, ...
-2
votes
2answers
199 views

Is this a good example of using the Dependency Inversion Principle?

So I have a high level module, that uses a low level module (I intend to use this example for language agnostic explanatory purposes, so I removed access modifiers, getters & setters etc.): Class ...
2
votes
3answers
340 views

How to not violate the single responsibility principle?

Let's say I'm writing a class that tracks a single stock ticker. In this simplified example, the StockTracker class holds a string that tells me the trend direction and a variable window that holds x ...
0
votes
4answers
162 views

Loose coupling in Python

While I know this is the tight coupling example: class User: def __init__(self): pass def get_status(self): api_client = APIClient() status = api_client....
0
votes
1answer
111 views

Have the same logic in two different class hierarchies

I have the following class hierarchies abstract class Base<T> { abstract T getRelevantType(); } class A : Base<AType> { AType getRelevantType() } class B : Base<...
7
votes
2answers
236 views

Data handling in SRP (single responsibility principle)

TLDR; Robert C. Martin adviced here: http://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html to split the multi responsibility classes into "single reason to change"...
0
votes
3answers
78 views

When to set constants during DI setup and when expect them on the fly as parameters?

Let's assume you have a project (e.g. .NET Core) using dependency injection. A database repository relies on a database connection string. public abstract class BaseRepository { // use this when ...
-2
votes
1answer
67 views

SRP for MVC controllers

I am trying to design an application that will be a REST API following MVC. For now ,I have 2 main features: Projects and Tickets associated to Projects. I would like to apply SOLID principles, and I ...
7
votes
3answers
414 views

SOLID, Does Liskov Substitution Principle (LSP) conflict with the Interface Segregation Principle (ISP)?

I am confused by the two principles of SOLID, liskovs substitution principle and interface segregation principle. It seem as though they conflict each other's definitions. How can a class that ...
2
votes
1answer
99 views

Application of Dependency Inversion Principle

Not a new programmer but new to architecture design. I'm about halfway through "Clean Architecture" by Robert C. Martin and I've realized that few components in my program need to have their ...
0
votes
0answers
165 views

Adaptive/split server API - what's a good way to design it?

I'll try to describe the scenario using a Turn-based game (such as card game or somethin'), where Game is the server, and the actual player is a client. (hence using Client-Server architecture), I'm ...
4
votes
2answers
189 views

How to design a SOLID pipeline with different inputs

I regularly have the situation that I have some complex logic that I break into steps. For example an import of an Excel file where I need to apply some logic or a complex calculation that I break ...
0
votes
0answers
44 views

Ways to refactor project to match SOLID principles [duplicate]

I'm learning Java and recently started to write my own project. The idea of this project is to pass one input argument - path to file/folder, which would be analyzed in order to find all files with ...
7
votes
3answers
204 views

Is a subclass Liskov Substitutable if it disallows the same invocation of the constructor in the child as in the parent?

Say, I have two classes: class FTPClient: def __init__(self, host, port): self._client = FTPDriver(host, port) ... class FTPSClient(FTPClient): def __init__(self, host, port, ...
5
votes
2answers
288 views

How to clean up a business logic class that does too many things without injecting a ton of classes into it?

Let's say we have business logic to perform in an MVC framework after a user submits a form: class BusinessLogic: def sendDataTo3rdPartyApi(self): # do stuff def validateResponse(self)...
0
votes
3answers
88 views

Is this the return type covariance issue PHP faced when type declarations launched, violation of Liskov principle, or flaw in my pattern?

I've been using a somewhat odd yet effective pattern for a current use case. The one issue is that I'm getting an undefined method notice on a method that is unique to the subclass. The method of ...
1
vote
1answer
169 views

How do I implement Dependency Inversion in C?

I'm a firmware developer and I'm interested in applying the SOLID practice in low level programming especially in Hardware Abstraction Layers in ARM microcontrollers. Every example I come across on ...
2
votes
1answer
60 views

How to determine whether the postcondition of overridden methods is weaker or stronger if there is no return value?

To reiterate the question - what does it mean to have a weaker or stronger postcondition when overriding a method that only does side effects with another one that only does side effects? P.S. What ...
2
votes
2answers
135 views

How can I improve this design to achieve a more loosely coupled system and better testability?

My question I built an inverted pendulum on an Arduino using C (ie. everything was done procedurally). I'm trying to self study application design and would like to refactor my code into a more OO ...
-1
votes
2answers
101 views

Do I name classes based on the object type they represent or the responsibility they have?

The more I read about the Single Responsibility Principle the less I see a class as an object type, but rather as a servant that does something. For example, let us suppose we have a new requirement ...
-2
votes
2answers
65 views

Best architectural practices [closed]

I want ask experienced software developers and architects about best architectural practices for the following problem. Suppose we have two entities: Student and Teacher and each of these two ...
0
votes
2answers
92 views

How to divide responsibility between poco, writer and converter

I have several POCO´s (simple classes holding data) that I have need to flush from memory from time to time whenever a collection grows too large. Most often I want to upload the data to a REST ...
1
vote
7answers
311 views

Understanding Open Closed Principle

I am confused about the Open/Closed principle. The principle says "open for extension, closed for modification". My thinking is that if there is a class and if you need to add any new ...
3
votes
4answers
185 views

Relationship between inheritance and single responsibility principle

Example 1: Let me assume that I have a base class A. Class B extends Class A (Class B is a derived class). Can I conclude, Class B doesn't obey single responsibility principle since it uses the ...
1
vote
1answer
81 views

Structuring application to comply with Single responsibility

I have the class AircraftManager that keeps track of a list of Aircraft objects and a list of AircraftListener objects. A DataSource (custom class, not sql related) object retrieves information from ...
0
votes
4answers
210 views

Open closed principle: code duplication and encapsulation

In another question on this site, asking to clarify the open closed principle, @Kate Gregory answered this. I'm interested in this part specifically: Imagine you wrote an Invoice class that works ...
1
vote
0answers
39 views

How can I decouple my wrapper API from its underlying SOAP implementation?

In our current architecture, a user has multiple ways they can change an address (as an example). They can do it through an online portal, through our core processor directly, or via a number of apps ...
-3
votes
1answer
48 views

Different input param for the same logic flow

I'm trying to find the best design approach to handle a design change in a new project I'm working on. At the moment, the flow runs and makes some calculations based on a parameter which is used. ...
4
votes
4answers
379 views

Do we really need interface classes for the dependency inversion principle?

As a practical example, imagine a Gripper class which represents a robotic gripper in a simulation. Gripper has a TryGrip method, which checks if there's a GrippableItem in the correct position (...
3
votes
3answers
269 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 ...
0
votes
1answer
64 views

How to detect class responsibilities? [duplicate]

Consider following class: public class Foo { public Foo() {} public void Bar(int input) { Console.WriteLine("Working on input ..."); switch(input) { ...
2
votes
3answers
264 views

UI Adapter Dependency on a Secondary (Driven) Port - Hexagonal Architecture

I am applying the Hexagonal Architecture (Ports and Adapters) to my system and I have noticed a dependency from my primary (driver) side adapter to the secondary (driven) side port. This doesn't seem ...
8
votes
3answers
2k 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
1answer
505 views

Single responsibility in python [duplicate]

The SOLID principle is supposed to be the underlying framework for object oriented programming. The "S" part stands for: "Single responsibility principle" which in wikipedia is defined as: A class ...
1
vote
2answers
83 views

Python subclassed methods with additional arguments

Given the following structure where I want a method with a common name for each class, but each derived class needs an additional piece of information in order to form the appropriate result. ...
4
votes
3answers
303 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
0
votes
2answers
145 views

Modify Command object inside decorator of CommandHandler(CQRS) or any other practice for avoiding duplication

Currently, we have multiple commands which share two same properties (BookName and ShopId). While handling those commands those properties must be validated with the help of some service. Let's say ...
0
votes
0answers
77 views

Angular 8: Mixing Business and Presentation logic

I was reading about the history of Microsoft and Webforms. How people strayed away from Webforms because it mixes business logic with display/presentation logic. So when reading Angular 8, and seeing ...
8
votes
3answers
545 views

Does it violate the Single Responsibility Principle if an object knows how to change itself?

I have worked with examples like a Player object which knows how to change its own state. Another example, is an Invoice object which knew how to calculate its invoice charges using an algorithm. ...
0
votes
2answers
446 views

c# Manage more Repository in UnitOfWork

I have a question about how can manage multiple repositories with unit of work. I thought for two solutions but I'm not sure. The first is a classic solution where the IUnitOfWork interface looks like ...
1
vote
3answers
248 views

Downcasting in order to call method of subtype

Is it a good practice to have a list containing objects of derived types and then filtering it by type checking when need to call methods specific for one of the types? From what I read typechecking ...
0
votes
3answers
145 views

How to properly apply open/closed principle on large code base for apparently unrelated features

Let's say I have a class hierarchy like this: Now let's suppose I add later a new interface Mechanic, responsible for repairing a vehicle. Of course someone capable of repairing a car won't fix your ...
7
votes
4answers
680 views

Changing States from child through parent while obeying SOLID principles

I'm trying to practise following SOLID principles. I'm a bit puzzled about following example (which is a remodel/artificial example based on actual code, which i cannot post here): public class ...
2
votes
6answers
651 views

What SOLID principles am I breaking with this code?

With the below pseudo code? Am I breaking any SOLID principles? interface i_pet string get_name() string get_species() color get_fur_color() end interface interface i_cat implements i_pet end ...
2
votes
2answers
478 views

Does SOLID Require an IoC Container (Automatic Factory)?

The fifth concept in the SOLID principle is the dependency inversion principle. It is heavily related to dependency injection, and Inversion of control, and when any of these concepts are mentioned, ...
1
vote
2answers
197 views

Declaring an object that extends a class and implements more than one interface

I'm confused about how should I declare an object that implements more than one interface, or derives from a class that implements one interface, and implements another interface itself. Let's ...

1
2 3 4 5
7