Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design.

Filter by
Sorted by
Tagged with
1 vote
2 answers
433 views

Chain of responsibility or simple dependency injection for Querying API

I am working on refactoring a project code that is wired up in a tangled way. It was started with decent dependency injection and over time with all custom requirements it looks it got tangled up. ...
3 votes
4 answers
1k views

Representing vectors as arrays of points vs. as data structures

I'm writing a program in Java where I need to represent the position, scale, and other 3-dimensional properties of objects in a world using vectors. I can use either of these two approaches: ...
2 votes
3 answers
205 views

Displaying a list of similar but different objects without resorting to type checking

I'm creating the UI for a "Point of Sale" type page. You can add orders, grouped orders, and custom items to your transaction, and it should display these in a list so you can see what you ...
169 votes
18 answers
294k views

Is it better to return NULL or empty values from functions/methods where the return value is not present?

I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take ...
5 votes
2 answers
3k views

Design patterns and multiple programming languages

I am referring here to the design patterns found in the GOF book. First, how I see it, there are a few peculiarities to design pattern and knowing multiple languages, for example in Java you really ...
1 vote
1 answer
222 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
125 views

Design of system pushing data to multiple systems

I have a ASP.NET Core backend (with Azure Service Bus) and a Blazor Server frontend. The purpose of the backend and the frontend is to trigger manual and automatic pushing of single data points (...
10 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 ...
6 votes
6 answers
462 views

Best practice to architect a system in which local users may override global definitions

Our travel industry client, operating across three continents and several countries, wants to standardize the process of choosing travel packages, air routes, hotels, and hundreds of other travel ...
10 votes
4 answers
14k views

Is "Introduce Parameter Object" actually a good pattern?

I have a situation where I want to call a function which requires a number of parameters. This function is not called directly, it is called indirectly and the parameters are delegated several times. ...
3 votes
1 answer
333 views

Data processing pipeline design for processing data

I have a use case for which I need to build a data processing pipeline Customer contact leads data coming from different data sources like csv, data base, api has to be first mapped to a universal ...
0 votes
4 answers
185 views

Best practice for using read-write lock

Given a system where users can access different services through the API for conducting business transactions, I am currently working on integrating a read-write lock into the system. One approach I ...
24 votes
11 answers
8k views

Is it logical to not use inheritance because the function is critical?

Our codebase has a typical base-class with a ton of sub-classes. The base-class already has many default functions for the sub-classes. However, one particular function has the same verbatim ...
13 votes
5 answers
3k views

What kind of logic can Domain Objects realistically contain?

I have been struggling with this concept in the context of web applications ever since I first read about it. The theory states that the domain objects should encapsulate their behaviour and business ...
2 votes
1 answer
105 views

Converting the classes with multiple dimension to Bridge design pattern

Bridge design pattern is something which is very confusing and GOF does not do justice with beginners in the definition. I was asked in my current organisation to add one more dimension to our class ...
1 vote
5 answers
231 views

DTO vs POJO (Entity) on POST request

If I have for example a User POJO like the following @AllArgsConstructor public class User { @Id private final String id; private String username; private String password; private Date createdDate;...
-2 votes
2 answers
169 views

Quiz Site Software Architecture Question

I am currently writing an application that is going to be an adaptive quiz-like site for studying. The idea is a user is studying some topic and they are given questions on the site and enter their ...
0 votes
4 answers
130 views

What is the advantage/disadvantage of returning a UnSubscribe class to Observer as opposed to just calling a UnSubscribe method of Observable?

There are two ways to provide a way unsubscribe in Observer Design Pattern. 1. Provide a simple void UnSubscribe method: public void UnSubscribe(IObserver observer){ // remove observer from List of ...
0 votes
1 answer
263 views

Writing Event Process architecture for multiple event handler interfaces

I am working on Java program which will listen multiple kind of events from multiple sources and store information to multiple sinks. Each interface will have its own source to listen and own sink ...
4 votes
1 answer
976 views

Help in writing more generic code

I'm doing a php MVC project using code igniter. I have two models, a and b. Each class contains four functions (insert, delete, update and view) and their implementations are almost the same with ...
0 votes
2 answers
127 views

Push and Pull Communication in object oriented: why Push style is not flexible?

I'm trying to learn Observer Design Pattern and I started to watch the series which belongs to codewithmosh called "The Ultimate Design Pattern Series". in the lesson which was about ...
0 votes
0 answers
93 views

By creating an architecture, it is better to have many classes that handles different scenarios, or a single one that handles all? [duplicate]

During my limited professional experience, I have been involved in microservices projects with a common structure: The Controller takes a request and validates it using the jakarta.validation....
1 vote
1 answer
94 views

How does a Bounded Context from DDD help scaling microservices?

New to the microservices architecture - but what I've picked up so far doing some research while designing a microservices architecture for a home rental system is these: Individual microservice ...
2 votes
2 answers
2k views

Repository pattern - using information from other repositories

I am trying to understand what is the proper approach when the objects generated from a Repository have a reference to objects which are responsible for another Repository. Let's say I have terminals ...
0 votes
1 answer
141 views

Separation of concerns: persisting complex types

I have the following module structure: core persistence extension In my core module, I have an interface: Handler. This interface has multiple implementations in the core module as well as extension ...
74 votes
7 answers
78k views

What is a helper? Is it a design pattern? Is it an algorithm?

Maybe a little tongue-in-cheek, but as I can't find this answer anywhere through Google, so to ensure Software Engineering has the answer: What is a helper? I have seen the name being used ...
2 votes
2 answers
232 views

How to design fault-tolerant distributed "all-or-nothing" system?

I have a system where Client(C) sends request to Server(S0). S0 then sends the response back to Client that "request received" and closes the connection. C can regularly poll S0 to check on ...
2 votes
1 answer
134 views

How do I structure my functions (and classes?) which interact with my Database/ORM?

So I am working on my first project using SQLite and SQLModel as ORM. Creating and handling the first table in my database was easily structured: A function for each CRUD-Operation. But now I have ...
3 votes
1 answer
102 views

Shell Script Design Patteren: Source a library file VS Call different files?

We discuss about POSIX compliant shell script here. While we are writing more and more shell scripts, we build some helper functions to reuse the codes. We are considering putting a few helper ...
57 votes
2 answers
18k views

What is the purpose of NaN boxing?

Reading 21st Century C I arrived at chapter 6 at the section "Marking Exceptional Numeric Values with NaNs", where it explains the use of the bits in the mantissa to store some arbitrary bit ...
1 vote
1 answer
258 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
1 vote
6 answers
377 views

How encapsulating what varies can help us?

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
2 votes
2 answers
505 views

Design of a modular application

I'm developing an application (Java) in a modular architecture. I have two approaches in mind and I'm not sure which one will be "better code" in case of maintenance and conventions. I have ...
2 votes
2 answers
170 views

Pattern to transform and cache data from a DB?

We have a server that receives queries. We use the command pattern for this, e.g. q := NewQuery(database) q.Execute(request1) q.Execute(request2) The queries read a "model" from the ...
0 votes
2 answers
127 views

Best way of creating different instance types(facotry method) with business logic?

Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types enum TableTypes { SMALL, MED, LARGE } I have ...
0 votes
2 answers
150 views

Appropriate design pattern for providing a default Argparse instance, eliminating boilerplate

I'm using argparse.ArgumentParser extensively; however, it comes with a lot of boilerplate to set up, and this is especially noticeable when you've got more than a few common arguments that probably ...
1 vote
2 answers
220 views

How to design relationships with constraints on subclass type?

I'm developing a full-stack Rest application following a narrative description of a working context. There is a class Job with two subclasses Job_A and Job_B. Job_A produces Report_A while Job_B ...
2 votes
1 answer
106 views

Decorate class which inherits from concrete class(es)

In my project I have several "basic" interfaces whose behavior is fixed, i.e. the default implementation will always be good for every puropse. So I defined them as concrete classes with ...
2 votes
1 answer
180 views

Did the term "decorator" originate with OOP design patterns?

The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have ...
3 votes
1 answer
2k views

Unit Testing in VIPER Architecture: Possible?

TL;DR There are no methods in VIPER which are returning any value so how to test them? Reasoning: In VIPER, each layer is communicating with other layer by holding an abstract reference to it (...
0 votes
1 answer
238 views

Is it okay to combine bff and rest api?

I'm building an application related to donation on streams. And I have such models as "alert" and "alert-template". "alert" is a set of different parameters to understand ...
48 votes
6 answers
58k views

Is "Mapper" a valid design pattern or is it a variation of the "Factory" pattern?

A common pattern I see is what's known as the Mapper pattern (not to be confused with DataMapper which is something else entirely), which takes as an argument some kind of "raw" data source (e.g. an ...
0 votes
1 answer
129 views

How best to share common steps between services while allowing them to provide their own behaviour

I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult: public IResult FooService(Foo foo) { ... } public ...
0 votes
1 answer
65 views

Load Testing for Large-Scale Architecture Involving Cloud Servers and Switches

We currently have an architectural setup as described below. Our plan is to conduct a load test, but we face a challenge due to the high cost of real switches. We have two options: either build the ...
2 votes
1 answer
610 views

Creating an internet gateway for a Bluetooth Low Energy device

I have a device that connects using Bluetooth Low Energy (BLE). I want it to communicate with a server over the internet using a smartphone as a gateway. I have thought of different approaches and I ...
0 votes
0 answers
92 views

Designing message handler

I am writing an application that receives different kinds of messages from an external device. The messages are of different types and they are received from the device in the form of a string. For ...
2 votes
1 answer
168 views

Design patterns for long chains of computations in python (functions vs classes?)

A recurring pattern which I see in my code is chaining together a lot of functions. This is the result of a large number of processing steps needed for a given task. This could be e.g. a data ...
0 votes
0 answers
142 views

better structure of a software project to prevent circular dependencies

I am contacting you today regarding a recent problem with circular dependencies. It's about a Spring boot application that accepts data via a Rest API and then forwards it to an internal Spring ...
0 votes
4 answers
2k views

Should an MVP/MVC Model contain behaviour?

I have read plenty of questions on here, which appear to confuse the MVP/MVC Model with the Domain Model. In my mind the MVP Model calls the Service, which then calls a rich Domain Model i.e. the MVC/...
1 vote
2 answers
2k views

Java Design for Data enrichment based on logic defined in a database

I have the following requirement. Read data from a messaging Queue and process each message to enrich the message and then finally send the enriched message to a different system. The enrichment ...

1
2
3 4 5
89