1,225 questions
Advice
1
vote
3
replies
64
views
Which design pattern should be used for the backend of a web application?
Description: I am building a web app, let's say about an organization for approving participation in a free service. There will be the following roles:
Organization employee
Citizen
Administrator
...
Best practices
0
votes
31
replies
200
views
Does dynamic_cast violate LSP?
Does the code below violates Liskov Substitution Principle (LSP)?
class Object
{
public:
virtual ~Object() = default;
};
class A : public Object
{
public:
void print()
{
std::...
0
votes
1
answer
78
views
In three-layer architecture, what do layer dependencies start to look like when OOP objects are involved in the Business layer?
As a coding test I've been tasked with developing a toy three-layer architecture DBMS project, involving OOP principles. The three-layer stuff isn't strictly my background so I've been trying to study ...
3
votes
1
answer
85
views
Sealed Class as Screen/Operation State
I'm working a little bit with VIEWS and I created those following seales class.
The first one to "hold" the state for the screen, it can only be Loading, Success or Error:
sealed class ...
1
vote
0
answers
105
views
How can I transform a monolithic state machine into a polymorphic state pattern when each state has unique extended methods and interfaces?
Please excuse me for how long this question is. I tried to shorten it as much as possible while still listing all of the various things I've tried and the problems I've run into.
I have a state ...
0
votes
0
answers
31
views
How can I reference private properties in TypeORM relationship decorators while keeping encapsulation?
I'm trying to follow best practices by keeping my entity properties private and accessing them via getters and setters, but I run into a compile-time issue when referencing private properties in ...
3
votes
1
answer
162
views
SequencedCollection interface in Java not following SOLID principles [duplicate]
In Java SE 21 there is an interface called SequencedCollection.
There are few built-in classes that implement that interface, including ArrayList and TreeSet.
The interface defines some methods, for ...
1
vote
1
answer
60
views
How to make Django Manager and Model's interactions follow the Open/Closed Principle?
I am designing models for my Django App and am concerned with decoupling the caller's logic from the model's implementation, so that future changes to the model itself do not require changes ...
0
votes
1
answer
138
views
Interface method argument without a type - code smell?
I'm thinking about creating an interface method with an argument that can have a mixed type, to act like metadata. I don't know the metadata type upfront, but I know that some kind of it (or something ...
-1
votes
1
answer
71
views
Abstract class design for a menu system in Unity: Static vs Dynamic Menus [closed]
I'm designing a menu system in Unity and need help validating my approach to ensure it follows the SOLID principles, particularly the Liskov Substitution Principle.
The system consists of:
A BaseMenu ...
-1
votes
2
answers
129
views
Dependency inversion principle
Here in this blog: https://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same/#db5adf784deb4c9b92a656627283c9da.
They said that changing the direction of the dependency between the ...
-1
votes
1
answer
45
views
Does an additional service class violates Single Responsibility Principle?
Let's say I have implemented an Action Design Pattern, and I have these actions:
MakeJuice
MakeCoffee
MakeBreakfast
MakeDessert
now, for every actions, as it should, have their own set of ...
1
vote
2
answers
241
views
Open/closed principles using Java
I have an exercise on the SOLID principle using java, specially on the open/closed principle and the exercise asks me to make a program the calculates the total area of different geometric shapes and ...
1
vote
2
answers
213
views
Private props return unmodified or losing values within the class inside scope of child class method
So, I have two classes service-class & entity-class with private constructor & static async method, for creating new instance of class. My service-class create & call new entity-class ...
-2
votes
1
answer
46
views
System Design-Decorator design pattern typescript
Requirement
create different type of decorator and used it with user class so we can add specific details of different type of user based on decorator and in my code I have two decorator one is ...
4
votes
1
answer
169
views
How to not violate Open/Closed Principle when checking for type is needed
I am writing a back-end for a program that manages surveys in TypeScript but don't know how to design my Survey and SurveyRepository class without violating the Open/Closed Principle (OCP)
My survey ...
2
votes
4
answers
116
views
Designing Models that are open for extension but closed for modification
Let's say I have some model code like the following with quite a few references in a moderately sized existing system:
public class House
{
public House(IEnumerable<Window> windows)
{
...
3
votes
2
answers
670
views
Does the Dependency Inversion Principle apply within application layers?
I keep reading code examples that suggest that the Dependency Inversion Principle is achieved by using interfaces for a classes dependencies. That in itself is confusing me, as the more I read about ...
1
vote
1
answer
213
views
Are interfaces required for the Dependency Inversion Principle?
I have read many examples about Dependency Inversion from classic SOLID in different coding languages.
// A is dependent on B
class A {
property;
constructor() {
this.property = (new B())....
-1
votes
1
answer
52
views
Violating Interface Segregation Principle (ISP) because of fat module
I'm working with TMDB API, This API has 2 improtant endpoints one for movies and the other for series.
right now working on movies, so i made an abstraction layer (module) to get data from that API
...
0
votes
1
answer
83
views
Does my design violate the Liskov Substitution Principle?
I'm working on a Spring Boot application with the following structure for sending messages
public interface MessageService {
void send(String message);
}
@Component("SendEmailService")
...
0
votes
1
answer
72
views
What is a "responsibility" in the single responsibility principle?
I'm taking a course on C# programming here: https://www.udemy.com/course/ultimate-csharp-masterclass/?couponCode=KEEPLEARNING
In it, there's a lecture on encapsulation. The instructor gives an example ...
2
votes
2
answers
108
views
How could I use DbContext in repository for implementing dependency injection principle in ASP.NET Core 8.0 MVC
I have created an ASP.NET Core 8.0 MVC app.
Here is my AppDbContext class:
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) ...
0
votes
1
answer
68
views
Managing controllers for identical entity structures? [closed]
I am developing a Spring Boot app and I am faced with the following situation:
I have x and y entities, but the fields of these entities are exactly the same, and because of this they both use the ...
0
votes
1
answer
53
views
Dealing with a Factory that uses both a Strategy and Repository
I've got a question around the best way to refactor a Factory like this:
I am working on a side-project and have ended up in a position whereby I have an OrderProductFactory that requires a strategy ...
0
votes
1
answer
58
views
i have 200 classes in my project, should i create per each class one interface?
this is actually an issue
so when we create an interface per class in a project
then when someone new join, it is gonna be really hard to keep track on the flow and the integration between classes
for ...
2
votes
2
answers
90
views
Question about interface segregation of a repository, when my services are interested only in one or 2 methods on the repository
I am wondering what can be the potential benefit if I start to split the interface of my repository which has GET/CREATE/DELETE/UPDATE methods
and in one service I have like 10 entities
which per each ...
5
votes
1
answer
143
views
Does composition violate the D in SOLID?
I am learning SOLID principle. While learning "Dependency Inversion Principle" found out that class should depend on interfaces rather than concrete classes.
Does this mean composition is ...
0
votes
0
answers
54
views
The most efficient method of Laravel dependency reduction?
Controller->Service->Repository->Model->all()
I have a construction in laravel(11). My code is as follows:
PostRepository.php
<?php
namespace App\Repositories\Eloquent;
use App\...
-1
votes
1
answer
250
views
Violating the Single Responsibility Principle? [closed]
We are creating a one-to-many relationship in a class, for example, a student can have many books.
In this class, are we not breaking the Single Responsibility Principle?
Because Student class has its ...
1
vote
1
answer
3k
views
Angular signals and immutable update of nested objects
I have 2 classes:
export class Enrollment {
private _productId = signal(0);
private _price = signal(0);
public productId = this._productId.asReadonly();
public price = this._price....
1
vote
1
answer
132
views
Is SOLID's Dependency Inversion actually Dependency Redirection?
I'm having a hard time trying to wrap my head around the Dependency Inversion principle of SOLID, I' think I might be mixing up concept with implementation... so I figured I could post my thought ...
2
votes
2
answers
122
views
Composition over Inheritance - code duplication
I would appreciate some clarification on how to properly implement 'Composition over Inheritance'. I think I have a grasp on the theory but in practice I struggle to understand how it doesn't lead to ...
0
votes
1
answer
111
views
Is this breaking LSP - Post condition rule
Wanted to know if I am breaking Liskov Substitution Principle - post-condition rule here,
public class ProcessController
{
public virtual Dictionary<int, string> GetRunningProcess()
{
...
0
votes
1
answer
72
views
Flutter Single responsibility principle with Provider package - clean code
I am trying to understand how to better write my Flutter application as right now with the current approach, the size of my service file is getting out of hand. Here is my use case (simplified):
I ...
0
votes
1
answer
76
views
SOLID principles: extract code in superclass
In my application I have N child classes all extending a superclass. Every class has its own implementation of serialize but they share some common code. For example:
class Serializer {
serialize = ...
0
votes
0
answers
191
views
How to relate canvas drawing objects with canvas controller objects in flutter (in SOLID correspondence)?
I need to create a simple 2D designer where user can draw shapes (triangles, rectangles, polygons etc) and also change already created shapes. I have three main classes:
Entity class Area. Contains ...
1
vote
1
answer
173
views
How to Implement Dependency Inversion and Interface Segregation for a Concrete Class that Needs to Be Initiated?
Context
So far as I understand, the Dependency Inversion and Interface Segregation principles of SOLID OOP tell us to write our program according to the interface, not internal details. So, I am ...
0
votes
2
answers
96
views
Liskov Substitution Principle: Confusion about additional Functionalities of sub types
I'm working on a social app using flutter, so there are posts to get published. Suppose there are two types of posts.
Post contains only text.
ImagePost contains images and text.
The following code ...
2
votes
2
answers
131
views
Is Dependency Inversion Necessary to Ensure Decoupling between Caller and Callee?
I am trying to understand the dependency inversion principle (DIP) via some simple, but concrete codes and classes (implemented in python) from this tutorial. I am summarising it (with my own comments ...
0
votes
1
answer
154
views
Clarification on Single Responsibility Principle: Actor vs. Responsibility
I need help understanding the Single Responsibility Principle (SRP) in software development. I know that SRP says a class should only change for one reason, but I'm confused about the difference ...
1
vote
1
answer
129
views
Where to instantiate my classes and still adhere to SRP [closed]
My questions is specific to adhering to SRP on the client side where we need to maintain state in our objects instead of adhering to SRP on the server where our state is maintained within a database, ...
2
votes
2
answers
567
views
Applying OOP principles to microservices
In the microservices architecture, the primary rule is to have autonomous services at all levels of design, including the database and domain model. However, in an application where the classes (...
1
vote
1
answer
430
views
One DAO per entity vs multiple DAO's per entity
Sorry for the long question. I have tried my best to articulate my thoughts as best I can. I am slightly confused with the common practice I hear of one repository per entity. Does this mean we have a ...
0
votes
1
answer
120
views
Breaking up methods leading to more operations
Breaking up methods/functions to do one thing only is considered a good practice as it leads to more maintainable and readable code but it increase number of operations in many cases . How to achieve ...
0
votes
1
answer
88
views
Entities can move from one use case to another using the controller?
I'm working on a project with the task of creating a route to checkout ticket purchases for events. In this scenario, I have a controller that receives the request with order data, client information, ...
0
votes
1
answer
91
views
Using an interface implemented by a struct to not depend on concretions but to depend on abstractions (SOLID)
I am trying to follow the SOLID principles in my new C# 12/.NET 8 project.
I will start by providing an example:
Given two separate assemblies AssemblyA and AssemblyB where AssemblyA defines an ...
0
votes
2
answers
247
views
Why is passing ViewModel in a Sheet View's constructor, it cause memory leak?
My goal is to conform to the Dependency Inversion principle. Meaning that SheetView should depend on Sheet ViewModel's protocol.
The problem is when I pass ViewModel to a Sheet View's constructor, ...
1
vote
2
answers
232
views
Is this UML diagram violating the Interface Segregation Principle?
I have created this UML diagram which applies the Template method design pattern:
Both concrete classes share a lot of the logic whithin the template methods createTask and completeTask, with small ...
2
votes
1
answer
91
views
Filtering inside a processing method vs. filtering outside
In my application I am processing a List of IMyInterface instances. Not all, but some of them in addition also implement IAnotherInterface. Note that IAnotherInterface not derives from IMyInterface. ...