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
0 answers
34 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 ...
user avatar
  • 1
0 votes
1 answer
97 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, ...
user avatar
0 votes
1 answer
86 views

Plugin architecture vs Interface Segragation Principle (SOLID) [closed]

Uncle Bob's Interface Segragation Principle (ISP) tells us that many client-specific interfaces are better than one general-purpose interface. But plugin architecture in common case suppose to have ...
user avatar
  • 113
7 votes
6 answers
326 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. ...
user avatar
  • 187
2 votes
3 answers
201 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 ...
user avatar
  • 101
0 votes
0 answers
40 views

Application of dependency inversion principle in designing tree

I'm currently refreshing my knowledge of Scala with Coursera Course Functional Programming Principles. In one of the assignment there is TreeSet structure designed like that: abstract class TweetSet ...
user avatar
1 vote
1 answer
257 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 ...
user avatar
0 votes
0 answers
38 views

Should ad-hoc values live in the component as class members, or not?

Say we have a recipe website with a recipe-list component which loads onto itself cards of individual recipes: <ul class="recipe-list"> <li *ngFor="let recipe of recipes"...
user avatar
  • 167
14 votes
5 answers
3k 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 ...
user avatar
1 vote
0 answers
82 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 ...
user avatar
  • 21
0 votes
3 answers
115 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 ...
user avatar
  • 13
1 vote
6 answers
244 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 (...
user avatar
0 votes
2 answers
85 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 ...
user avatar
0 votes
1 answer
86 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 ...
user avatar
1 vote
1 answer
59 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 ...
user avatar
  • 13
-1 votes
2 answers
114 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 ...
user avatar
0 votes
2 answers
62 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 ...
user avatar
1 vote
4 answers
213 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 ...
user avatar
  • 287
0 votes
2 answers
74 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 ...
user avatar
2 votes
2 answers
207 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; ... ...
user avatar
  • 87
1 vote
1 answer
114 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: ...
user avatar
  • 157
2 votes
3 answers
154 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 ...
user avatar
1 vote
1 answer
174 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 ...
user avatar
2 votes
1 answer
193 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{}; ...
user avatar
1 vote
1 answer
100 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"; } ...
user avatar
  • 221
2 votes
2 answers
146 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 /...
user avatar
  • 145
4 votes
2 answers
122 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; ...
user avatar
2 votes
1 answer
122 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 ...
user avatar
2 votes
2 answers
325 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 ...
user avatar
0 votes
2 answers
124 views

Improving dependency inversion principle

Reading a little bit about Functional core & imperative shell pattern, I am wondering if the DI principle can be improved. What happen if instead of having an Infrastructure layer depending on ...
user avatar
3 votes
4 answers
423 views

Do Private methods in subclasses violate Liskov Substitution Principle?

I have searched for this question but could not find a good answer for my case. Suppose I have a SuperClass for a bank loan with properties Amount and InterestRate. public class BankLoan{ public ...
user avatar
-3 votes
2 answers
109 views

Do classes that set, get and calculate data follow the S in SOLID?

Supposing I live in a country where every car brand has a different tax rate, and I have a base class called Car public class Car{ public string CarType { get; set;} public int Year {get; set;}...
user avatar
-1 votes
2 answers
133 views

What design/component principle did I apply? How can I further improve it?

I recently refactored a program for code feasibility and maintainability; however, I am totally unaware of what software principle I did implement. I just followed my feeling. The purpose for this ...
user avatar
  • 185
19 votes
9 answers
4k views

Which object should have the method?

I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
user avatar
0 votes
4 answers
226 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 ...
user avatar
3 votes
3 answers
251 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 ...
user avatar
1 vote
1 answer
163 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);...
user avatar
  • 211
11 votes
2 answers
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 ...
user avatar
  • 6,711
-1 votes
1 answer
45 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, ...
user avatar
  • 139
-1 votes
2 answers
219 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 ...
user avatar
  • 260
2 votes
3 answers
480 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 ...
user avatar
  • 139
1 vote
4 answers
1k 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....
user avatar
  • 231
0 votes
1 answer
245 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<...
user avatar
  • 119
7 votes
2 answers
420 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"...
user avatar
  • 181
0 votes
3 answers
82 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 ...
user avatar
-2 votes
1 answer
221 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 ...
user avatar
  • 145
8 votes
3 answers
2k 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 ...
user avatar
2 votes
1 answer
124 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 ...
user avatar
  • 31
4 votes
2 answers
224 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 ...
user avatar
  • 189
7 votes
3 answers
257 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, ...
user avatar

1
2 3 4 5
8