Questions tagged [object-oriented-design]

Object-oriented design is the process of planning a system of interacting objects for the purpose of solving a software problem.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
90 views

Avoid use of the visitor pattern in this very common scenario

Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it. We already know that we ...
1 vote
1 answer
156 views

Is the Target interface really necessary in adapter design pattern?

I saw a code example online that uses adapter pattern as: if you look at the HR system, the employee information in the form of string array and the ProcessSalary method of the Third Party Billing ...
2 votes
2 answers
171 views

Efficient way to Decouple classes in class design

I am working on a class design question - design a simple grocery store with a self-checkout system I am a beginner After briefly jotting down requirements, I started with the Product class as follows ...
0 votes
1 answer
143 views

Distributing responsibilities in a micro service in an Object Oriented manner for a 3rd party integration?

I'm trying to figure out how to structure a 3rd party integration microservice, and how to name the classes accordingly. If you had a classic shopping cart application which processed payments for ...
1 vote
1 answer
161 views

Newbie: OOP working with different class-datatypes and loop through them

I'm relatively new to OOP. Let's say I have three different objects/classes defined, like: Public Class Part Private m_Name As String = "" Public Property Name() As String ...
1 vote
2 answers
770 views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
3 votes
2 answers
218 views

Creating an abstraction just for exception handling - a pattern or anti-pattern?

Assume that an external library or framework not under our control exposes a Controller API: abstract class Controller { abstract fun call(): Result } Assume that we want to handle exceptions ...
-1 votes
1 answer
79 views

How can I prevent an object from being re-sanitized everytime it is passed as input to a function?

Suppose that I have a class named CharStream Additionally, there are a large number of functions which convert their function input into a CharStream def funky_the_function(_input): input = ...
1 vote
2 answers
186 views

Why do we separate interface when implementing interface injection variant of DI?

With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase. public interface ServiceSetter { public void setService(Service service); } Why ...
4 votes
4 answers
969 views

Are arrays -as data structures- suitable for constructors?

My question comes from this other question. The first time I read the question, I understood (maybe worngly) that the OP was asking for a different way to initialize the object in such a way that it ...
0 votes
1 answer
38 views

Is it OK to stick with object graph in React State and should I make helpers for handling it?

I am trying to build ERP application using React frontend and I have not found decisive answer whether to use object graphs in React state? E.g. I would like to build Invoice view and I have the ...
2 votes
2 answers
105 views

Pattern for a base class to do pre-validation and/or post-processing on a deriving class's overridden method?

I have the following pattern repeating itself in multiple places: abstract class Database { void connect() { this.setStatus( CONNECTING ) try { await this.realConnect() } catch ...
0 votes
2 answers
57 views

Where to specify UI views in a hierarchy of model objects?

In a Flutter app I'm developing, I have a class hierarchy of model objects of a certain base class. To take a typical example, the abstract base class could be Vehicle. Then I have a (pretty much) ...
1 vote
1 answer
94 views

Wrapper class for min/max clamping and validation

I have a lot of classes that have numeric values that are configurable by the customer during runtime and should be clamped between a min and a maximum value. The value changes should also be logged. ...
5 votes
2 answers
644 views

Best way to refactor service with too many dependencies

We are creating the backend for a web app using a sort of layered architecture. The service layer is supposed to handle the business logic and passing data to the repositories. This service layer is ...
-1 votes
3 answers
145 views

Is it better to override methods in classes or make methods general?

I am creating the backend of a microservice that will serve as a tool to see in real time how the company's employees are distributed by projects and what days they have assigned to each one. The ...
9 votes
3 answers
2k views

Balance between aggregate boundaries and domain consistency in DDD

Designing an Aggregate and choosing an Aggregate Root getting tricky for me all the time especially when it comes to ensuring right transactional contexts and consistency constraints so I'm wondering ...
149 votes
12 answers
26k views

Is this a violation of the Liskov Substitution Principle?

Say we have a list of Task entities, and a ProjectTask sub type. Tasks can be closed at any time, except ProjectTasks which cannot be closed once they have a status of Started. The UI should ensure ...
1 vote
2 answers
101 views

Designing Products with multiple variations

I have a Product entity: public class Product { public int Id { get; set; } public string? Name { get; set; } public string? Description { get; set; } [ForeignKey("Brand"...
0 votes
3 answers
228 views

Specialization and LSP violation?

I have Document and ExternalDocument classes in my system, where ExternalDocument extends Document. The main distinction is that ExternalDocument holds onto externalDocumentId and externalEventId data ...
1 vote
1 answer
155 views

State Pattern when the Behavior in Object of Type A is Dependent on the State of the Object of Type B

I have used the state pattern for my web application where a user can be in one of three states: activated, required_activation and suspended. I have created 3 states classes as given below (source is ...
0 votes
1 answer
55 views

Separating model and applicative user in app

I am working on a mobile application, and I want to plan a separation between the model layer that represents a user (that comes from the server) and the "applicative" user that has the same ...
1 vote
2 answers
89 views

Sharing a data class in a flow

Suppose there is a flow of functions in C++ step1(); step2(); step3(); step4(); step5(); and they interact by adding and modifying data on a data class D (only data, no functions). For example, step1(...
0 votes
1 answer
131 views

Validation in a simple DDD example

I'm doing a simple project that represents a CI Pipeline in a low scale. So I'm trying to model "the best way possible" to practice DDD. Basically I have the following information: ...
0 votes
0 answers
164 views

How can I allow sub-services to use concrete types, without having an ever-growing type argument list on the primary service?

NOTE: I believe I have a bit of an X/Y problem here, so please, bare with me. Also, I have trouble explaining things sometimes, so feel free to ask me to elaborate, and I will improve anything I can ...
0 votes
2 answers
119 views

Is there a UML symbol representing instantiation? This one doesn't seem to be one

The following figure comes from https://spring.io/guides/topicals/spring-security-architecture I refer to it as a "figure" rather than a "diagram" as I'm not sure if it is. the ...
0 votes
2 answers
161 views

How to handle a new method in the interface that is not applicable for all classes?

I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that ...
2 votes
2 answers
588 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 ...
-1 votes
2 answers
159 views

Liskov Substitution Principle Edge Case

I thought I understood Liskov Substitution Principle but then I thought of a case and I wanted to ask the community here if I get it right. So I read somewhere to check if we have violated Liskov or ...
1 vote
1 answer
89 views

Creating a new type as slice of strings in Rust?

I have a little bit of experience with Go, that I have been trying to use as a reference point to wrap my mind around Rust via a cards game I wrote in Go that I would like to now write in Rust. I know ...
2 votes
1 answer
65 views

Can we use external parties as objects in a sequence diagram?

I am currently building a sequence diagram for a website to allow customers to make online bookings for a travel agency. If a customer books a flight, he/she can use an online payment method to pay ...
12 votes
6 answers
1k views

How to avoid violating the SRP in a class to manage caching?

Note: The code sample is written in c#, but that shouldn't matter. I've put c# as a tag because I can't find a more appropiate one. This is about the code structure. I'm reading Clean Code and trying ...
1 vote
1 answer
100 views

Representing database tables as objects

I'm building an address book API, where a user can input multiple contact names, phone numbers, and addresses. My database structure would be as follows: create table user ( id int not null primary ...
0 votes
1 answer
116 views

Pattern to convert different types of similar unchangeable objects to the same object

I have an existing system that inserts books into a library database, and I want to generalize it to include other media. The other media is similar, but not exactly the same, and all media are third ...
1 vote
1 answer
106 views

What to use in B's configuration: A or A's configuration?

When I have a class A in a module amod as follows // module amod type AConfig = { x: number; // ... }; class A { constructor(public config: AConfig) {} // ... } export {A, type AConfig} ...
2 votes
2 answers
235 views

Types with same name, same concept, but different... runtime uses?

I keep running into this problem when programming, and I wonder if someone has written about it before, or maybe developed some ideas about it. For an example program, lets say I have a graphics ...
21 votes
6 answers
6k views

Does subclassing int to forbid negative integers break Liskov Substitution Principle?

In Python 3, I subclassed int to forbid the creation of negative integers: class PositiveInteger(int): def __new__(cls, value): if value <= 0: raise ValueError("value ...
-3 votes
1 answer
234 views

What's the right data structure to combine iteration of key-value pairs, and iteration of values

I'm looking for a pre-existing or easy-to-build data structure available in Java, which can do these 2 things efficiently: Fetch all the values stored in the collection quickly. Iterate over the data ...
0 votes
0 answers
182 views

Avoiding forward declaration and circular reference in C++

Consider a card game (something like Magic or Legends of Runeterra) program, with BaseCard, Deck and GameState classes/structs. The way I've conceptualized the relationship between these classes would ...
56 votes
11 answers
4k views

What is meant by, "A user shouldn't decide whether it is an Admin or not. The Privileges or Security system should."

The example used in the question pass bare minimum data to a function touches on the best way to determine whether the user is an administrator or not. One common answer was: user.isAdmin() This ...
0 votes
2 answers
253 views

C# coding style, functional approach

I have thought of this for a while and I want to know what you think about this. This is more of a way to structure the code that might not be 100% object oriented and that is not the purpose. I would ...
6 votes
2 answers
2k views

Is it acceptable to define a "module" and "class" within a single .VB element?

Experiment: I have found it is possible to define both a "Module" (Namespace?) and a "Class" (Namespace?) within a single .Vb element (Module??). You can try this at home: Create ...
1 vote
1 answer
601 views

Can Domain Services publish Domain Events on multi-aggregate operations?

I'm in a scenario where, when a certain command is applied on an aggregate, I have to change the state of the aggregate itself if ALL related aggregates are in the same state, then notify the world ...
2 votes
5 answers
2k views

Declaring unnecessary variables for readability

I know some languages (C comes to mind) its best to declare as few variables as possible. In a language with memory management like C# is it better practice to continue with this philosophy or should ...
3 votes
4 answers
384 views

Should I implement one interface with two methods or two interfaces?

NOTE: This question is reposted from SO because it violates community guidelines for being opinion-based. I have two classes that are similar in nature but they have different functional signatures. I ...
2 votes
1 answer
206 views

Interface segregation principle

Let's say we have the following business requirements: We have a list of dishes. They have a name and a list of ingredients. The restaurant owner always wants to have a dish (and only one) marked as ...
0 votes
0 answers
57 views

From the ECB & DAL perspectives, is this design acceptable?

I've been recently trying to go slightly further in arch. patterns (specifically layered arch.). I decided to go though an old project of mine (a CLI-based cinema reservation system) and evaluate my ...
0 votes
2 answers
287 views

What are the considerations between a class variable and a global variable

At first glance, these seem equivalent. If one has the right visibility, one can access a global variable or a class variable from anywhere in the program; There is only one, shared copy of them. So ...
0 votes
2 answers
114 views

Shared logic to different types

I have several services and each of these services has interfaces for each. I need to add a shared execution strategy here. By designating two classes with the same inheritance relationship as primary ...
2 votes
1 answer
62 views

Allow\disallow actions in one system based on the state of another

Subj - how could I allow\disallow actions in my system based on the state of another external system (I have access to it's state via the shared DB table)? I can get the state of another system almost ...

1
2 3 4 5
34