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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

0
votes
0answers
73 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
204 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
369 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 ...
2
votes
1answer
107 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
33 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 ...
3
votes
1answer
111 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
104 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
193 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 ...
0
votes
5answers
137 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
109 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
533 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
84 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
80 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
10k 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
97 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
130 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
123 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
103 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
211 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
331 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
341 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
127 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
811 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
119 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
74 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
429 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
193 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
141 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
0answers
134 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 ...
2
votes
2answers
503 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
262 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
482 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
243 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 ...
7
votes
3answers
1k views

How to use 'Adapter' without any changes in the existing code in c++

Here we have TV class and DVD class as example: class TV { public: TV(); virtual ~TV(); void on() const; void off() const; }; class DVDPlayer { public: DVDPlayer(); ~...
3
votes
3answers
150 views

Liskov substitution for voids and weakened preconditions

I am learning a lot about this principle (also thanks to two answers I received here) and would like to elaborate on another point that somebody mentioned. 1) Is the following a violation of LSP? ...
7
votes
6answers
2k views

Liskov Substitution principle - strengthening preconditions

I am a bit confused as for what it really means. In the related questions (Is this a violation of the Liskov Substitution Principle?), it was said that the example clearly violates LSP. But I wonder, ...
5
votes
1answer
142 views

Dependency Inversion Principle (Swift) - Applicable also without polymorphism? (Abstraction: constrained generics)

There exist a number of articles/blogs explaining the Dependency Inversion Principle (DIP) using Swift; to name a few (top Google hits): GitHub/ochococo/OOD-Principles-In-Swift - The Dependency ...
3
votes
3answers
662 views

Following Open Closed Principle

I try to write "clean code" for most of the time. But practically find it very hard, meaning - gradually business requirements changes dramatically or the business requirement which seems like just a ...
13
votes
2answers
2k views

Stack extending LinkedList. A violation of Liskov Substitution Principle?

A class LinkedList exists with functions such as add_first(), add_last(), add_after(), remove_first(), remove_last() and remove() Now there is a class Stack that provides functionalities such as push(...
12
votes
5answers
617 views

Is it useful to mini-refactor code in hopes of improving quality, or is it just “moving code around” without much of a benefit?

Example I came across monolithic code that does "everything" in one place - loading data from database, showing HTML markup, acting as a router/controller/action. I began applying SRP moving ...
9
votes
5answers
1k views

Is it a violation of the Open-Closed Principle to update a constant representing a real-world value?

I have a class calculating workers' net yearly income. It has a constant representing a tax percentage. But one day the tax rate has changed, so I need to fix the code. Does the act of fixing this ...
9
votes
7answers
724 views

Circumventing the Rules in Wizards and Warriors

In this series of blog posts, Eric Lippert describes a problem in object-oriented design using wizards and warriors as examples, where: abstract class Weapon { } sealed class Staff : Weapon { } ...
3
votes
3answers
284 views

SOLID principles in this class

I want ask experienced software developers and architects about this domain class which I found one day in some code. public class User : Entity { public virtual string Firstname { get; set; } ...
4
votes
4answers
434 views

Is SRP an ambiguous principle? [closed]

I've been aware of SOLID for many years now and I've always though about "OLID" was a good set of design principles to follow... problem is I've always found difficulties with the "S", I've always ...
4
votes
4answers
408 views

Please explain why we need SRP in “Plain English” despite its drawbacks?

Can you in "plain English" explain why we need Single Responsibility Principle? Especially that it moves the what I call "bloat" into other places. See below for more info. By bloat I mean in my ...
5
votes
3answers
517 views

Separation of concerns for a “Manager” class

I have a Class that "controls" the current application state, ApplicationStateManager. I have an Enum that lists the possible states for the application enum ApplicationState { Idle, ...
0
votes
3answers
244 views

Can Composition violate the O in SOLID

I was reading about composition and I'm wondering if it violates the O in SOLID, and what should be done to fix the situation. In the article the author uses a Fruit and an Apple. At the end the ...
1
vote
1answer
74 views

Refactorings of larger types

This is a sweet spot thing for me. But I am not sure what rules others apply to the challenge. In this codebase I have many large types. Mostly types called *Service. Large types are cool. But I tend ...