Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [solid]

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

1
vote
1answer
114 views

Is it a good design to create an interface that inherits from multiple interfaces to reduce the amount of dependencies of a client?

I was refactoring an application to respect SOLID principles. When I was applying interface segregation I found the following case: interface A { void methodA(); void methodA2(); } ...
0
votes
1answer
475 views

Why does the Square–Rectangle problem violate SOLID principles?

My previous question was just with class diagram and because of some comments I thought I try to find an example with a little piece of code for the diagram to see if principles correct understood? ...
1
vote
2answers
346 views

Which SOLID principles are broken by this class diagram?

I just read about all the 5 principles S,O,L,I,D and I like test it in little example if I understand them correct. Which SOLID principles are hurt by this class diagram? I think what is broken is ...
1
vote
3answers
482 views

Convincing a development team to use a better design pattern [closed]

I recently joined a company where I was tasked with building a system for one of their clients. The work I've done is so far working well, but the most senior developer on the team who's been with the ...
1
vote
0answers
48 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 ...
3
votes
2answers
113 views

Clarification about an example of the polymorphic open/closed principle

My question is regarding the polymorphic Open-Closed Principle. Say I have the following client: public class Client { private Server server; public Client(Server server) { this....
70
votes
4answers
7k views

Does following SOLID lead to writing a framework on top of the tech stack?

I like SOLID, and I try my best to use and apply it when I'm developing. But I can't help but feel as though the SOLID approach turns your code into 'framework' code - ie code you would design if you ...
1
vote
2answers
225 views

Liskov Substitution Principle

I am trying to wrap my mind around a Liskov Substitution Principle and I came across this article. SOLID Class Design: The Liskov Substitution Principle In this article, the author gives an example ...
1
vote
2answers
196 views

How to interpret Dependency Inversion Principle

I am working on trying to understand the SOLID object oriented design principles. I was able to get the "SOL" pretty easily, though "L" required some hand holding because I am bad at definitions. I ...
1
vote
1answer
166 views

to ISP or not to ISP?

I've got a design problem, and I figure it's not something totally uncommon so there must be some good practices out there. I have 2 domain entities: Process and Task. A Process is essentially a list ...
1
vote
0answers
154 views

Handling complex dynamic queries in Laravel 5

I am developing a project using Laravel. My workflow is: route directs to controller Controller calls eloquent models Eloquent models perform queries (tipically CRUD and find) Controller returns ...
2
votes
2answers
163 views

Changing Behavior - Special case in a loop

I have a module as below: def normalize(sub_item): pass def process(sub_item): pass def cleanup(sub_item): pass def calculator(item): pass def main(item): for index, sub_item ...
-1
votes
1answer
110 views

MVC / MVVM principles

I'm currently working on updating some old projects (inherited stuff) and I keep running into various small issues with the architecture. Namely monolithic classes too tightly coupled. One example ...
1
vote
0answers
75 views

What Design Pattern to use to render PDF pages for a PDF Proposal?

I want to create a set of patterns to use for rendering a PDF Proposal (a set of PDF pages). I have made a good start, but not clear on how to proceed when more complexity is involved. I am using ...
2
votes
1answer
52 views

Abstraction for Account transactions and balance

We have 10 applications which updates account balance table, without logging credit/debit line transactions (not sure why). They all have the pretty much same SQL Statement. In order to get out of ...
0
votes
1answer
161 views

Architecture / Design Pattern for Login Signup

I have a multi-seller ecommerce platform, derived out of Opencart 2.3. We changed quite a bit of the core code of the Opencart to add our own customizations, including features such as Seller ...
4
votes
2answers
222 views

Is it violation of single responsibilty to add a method to an existing API

Say i have a Rest API that has a POST and GET method. If i want to overwrite a resource in the API i can call the GET method to get the original item and then call the POST method to replace that ...
3
votes
4answers
410 views

Is Abstracting your code too much a bad use of SOLID Principles?

After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come ...
1
vote
1answer
186 views

Domain driven design - factory with cross-cutting concerns

I was recently tasked with creating a factory that processes webhook events. Any authorized application in the solution (1 app per domain) can post any meaningful payload and as long as the event's ...
0
votes
0answers
89 views

MVVM composite ViewModel for sharing fuctionality (instead of inheritance)

I'm looking for design ideas for something like a composite ViewModel. I'm facing a situation where a lot of ViewModels need CRUD operations and some need refresh operations. A minority of ViewModels ...
4
votes
1answer
352 views

Should unit of work create repository?

Our "unit of work" class has a method which takes a class type and creates a repository: public IRepository<TEntity> GetRepository<TEntity>() where TEntity : class { ...
-1
votes
1answer
129 views

Does Interface Segregation Principle apply to parameters/request objects?

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a ...
30
votes
9answers
5k views

Designing a Class to take whole classes as parameters rather than individual properties

Let's say, for example, you have an application with a widely shared class called User. This class exposes all information about the user, their Id, name, levels of access to each module, timezone etc....
1
vote
2answers
209 views

Does it violate SRP to reject subclass method parameter

I was having a good read on Eric Lippert's blog about Wizard and Warriors. It suggests the creation of a Rules class, quote: We keep on talking about “rules”, and so apparently the business ...
1
vote
5answers
216 views

Single Responsability actor or use case?

I've been struggling to grasp my head around the SRP pattern, because I dont know if it refers to a actor o to the use case. In the following case: To don't violate the SRP, would you need to create ...
-1
votes
2answers
113 views

Reconciling the Interface Segregation Principle with the need to uniquely identify an object

I have an interface ICondition which only defines a single method, IsConditionMet This works well as it is the only information the parent entity needs from its conditions. However, there is a ...
7
votes
2answers
627 views

Liskov's substitution principle : If subtype has some extra behaviour implemented, which is not present in type, then is this violation of LSP?

In my quest to write better, cleaner code, I am learning about SOLID principles. In this, LSP is proving to be little difficult to grasp properly. My doubt is what if I have some extra methods in my ...
0
votes
1answer
86 views

Modeling web scraper

I'm working on a small application that is supposed to scrape/parse a few website and I'm wondering which would be the best way to achieve this (keeping DRY/SOLID in mind). Here's some pseudocode: ...
-2
votes
1answer
163 views

Can I use DI with client of Abstract Factory pattern c#

Let's say I have something like this: switch(i) { case 1: new Class1();break; case 2: new Class2();break; } So what's the best practices of doing this if in class where I placed ...
42
votes
8answers
11k views

Class that does not represent anything - is it correct?

I am just designing my application and I am not sure if I understand SOLID and OOP correctly. Classes should do 1 thing and do it well but from the other hand they should represent real objects we ...
3
votes
2answers
146 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)...
-1
votes
1answer
152 views

OO Class Design for ATM card

I have to design a Class for ATM cards with the following attributes: Cardholder Name Card Number Pin Other than getters and setters, I have a method to validate the pin of the ATM. As per the ...
2
votes
2answers
147 views

Wrapping 3rd party objects that are dependant upon each other and best practices

I'm having a bit of a moment of indecision here and I'd like some perspective on it. I'm currently wrapping up objects from a 3rd party API (at home for my own project and at work), and I'm doing my ...
4
votes
1answer
110 views

Design pattern to instantiate implementations depending on properties

I have an interface: public interface MyInterface{} And two implementations: public class Imp1 implements MyInterface {} public class Imp2 implements MyInterface {} My program is a CLI. I want to ...
1
vote
0answers
259 views

What are a few arguments against SOLID principles? [closed]

I've been practicing SOLID in my code-base (PHP) as best as I could as of late and the progress is clear. Code is more readable, more maintainable and everything in-between. The problem is that I ...
4
votes
2answers
379 views

I'm struggling to see how dependency inversion doesn't lead to tighter coupling in lower level modules and less reuseability

I'm refactoring a project I did for my work and I'm trying to apply the SOLID principles to make the architecture cleaner. I've run into an issue with the Dependency Inversion Principle that I can't ...
7
votes
4answers
344 views

A few classes versus 20 classes? A question about bloat [closed]

In evaluating the work of an outsourcing company, I have found that they have a propensity for dividing work into as many classes as possible, each one being testable. In some ways this seems ...
2
votes
2answers
128 views

Is replacing the call to mutual exclusive methods by an injected strategy overengineering?

I recently gave advice to refactor some code along the lines of class Validator<T> : IValidator { public ValidationResult Validate(Validatable thingToValidate) { if(typeof(T)....
5
votes
5answers
1k 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; ...
-3
votes
2answers
160 views

C#. Pattern for dynamic report creation

This is a simplified example, the actual problem has more reports and data points that are requested. Also, more reports could be added in the future so I would like to have something "smart" and ...
0
votes
0answers
77 views

Why does Qt consider disconnectNotify as violating the modularity of OOP?

Source It is stated that disconnectNotify is violating the OOP concept of modularity, why? Isn't it considered like LiveData of Android ? If it is really violating modularity, what was the ...
33
votes
6answers
7k 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 ...
0
votes
3answers
455 views

S.O.L.I.D. principles

I have a small question. Which approach is correct in the context of SOLID principles? 1 or 2 ? In the first case, the "CreateTask" method does not return the Task object, but places it on the list ...
4
votes
4answers
201 views

Software design strategy for a functionality that depends on a temporal situation

First of all please excuse my english mistakes; it's not my native language. Second, I couldn't find a better title to summarize my inquiry, so let me explain it below: Let's say we have a software ...
3
votes
1answer
175 views

How Dependency inversion is an extension of OCP?

I am reading about SOLID principles and have just read that Dependency Inversion (DI, to be distinguished here from Dependency injection, which is one way of achieving the inversion) is an extension ...
0
votes
2answers
232 views

Achieving Liskov-compliant contravariance in method arguments in C#

Trying to practice LSP, the following is not really clear to me: Liskov requirements (some) -There must be contravariance of the method arguments in the subtype. – There must be covariance ...
3
votes
2answers
727 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 ...
3
votes
2answers
304 views

Liskov principle: subclasses can have stronger invariants. How could it work?

Learning about the Liskov principle, I do understand that preconditions can be weakened and postconditions can be stronger in subtypes. However, I do not understand how invariants can be stronger in ...
14
votes
3answers
555 views

Can the RxJava class Flowable legitimately have 460 methods?

I am just getting started with RxJava, Java's implementation of ReactiveX (also known as Rx and Reactive Extensions). Something that really struck me was the massive size of RxJava's Flowable class: ...
7
votes
3answers
279 views

How to be OCP compliant and change algoritms?

I am not working yet, just studying and recently dealing with SOLID principles. I have read quite a lot about open closed principle but unfortunately most of the books and articles share the same ...