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
-2 votes
1 answer
70 views

Pattern for flexible promotions/badges [closed]

Let’s imagine system like Garmin connect, you run, record your workout and then once you finish workout is uploaded to the system and being analyzed. Based on analysis you can receive badge: for 5 km ...
Snorlax's user avatar
  • 117
1 vote
0 answers
72 views

How to have only one consumer handle a long running task at a given point?

I need to design an application which makes requests to an external API. External API has a hierarchy of entities: User which contains ListOfItemss which contain Items. I need to get data on all Items ...
Yos's user avatar
  • 157
0 votes
1 answer
157 views

C# Best Practice DI Pattern?

Is there a best-practice pattern I can/should use for this scenario? I need access to some DI services in the OnFinished() method: public class Product { public int Quantity {get;set;} } public ...
mxmissile's user avatar
  • 103
2 votes
3 answers
435 views

What is the name, or design pattern, for something that calls a list of functions one by one?

The following design emerged from using Azure Durable Functions with lots of fan out, which turned out to not work very well. Our starting point was an Orchestrator with a companion Durable Entity for ...
Thomas Eyde's user avatar
0 votes
1 answer
333 views

Where should I create my aggregate root? in api or frontend?

I am writing a simple application to apply what I have learned so far in DDD. I have the following mysql tables in my api server Sales Column id pk, int title varchar description varchar Images ...
emhsmath's user avatar
0 votes
1 answer
649 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 ...
Kee's user avatar
  • 13
0 votes
1 answer
312 views

Multiple models/controllers python app

I am trying to tinker with the MVC pattern and I have a problem when trying to design the MVC structure. I need a model for products, however as I need to manage more and different data, I can help ...
Eideann's user avatar
  • 13
2 votes
3 answers
870 views

CQRS in a data heavy application involving a lot of CRUD

I've been developing a non-trivial personal application and I thought I'd use CQRS to learn it. The application is very data entry heavy, lots of entities and lots of forms. I find myself constantly ...
David's user avatar
  • 153
0 votes
1 answer
941 views

What design pattern / solution helps me elegantly map classes that share the same base class

I'm looking for an elegant way (a design pattern if such exists, not a library) to map two classes that share the same base class, without duplicating the code that maps the properties of the base ...
Joep Geevers's user avatar
2 votes
1 answer
226 views

C++ behavior as a template argument

I would like to have a class, let's say a queue, that can be specialized to its behavior. For example, let them be a SafeQueue (which disables IRQs before any access) and a FastQueue (which doesn't). ...
JD.'s user avatar
  • 131
1 vote
1 answer
3k views

Return type specification if a Python function output type, is dependent on the input arguments of that function?

Context Suppose one has a list of algorithms, which each have a multiple run/parameter configurations. Next, one wrote a generic function def get_mdsa_configs(self) -> List[MDSA_config]: that ...
a.t.'s user avatar
  • 225
2 votes
1 answer
674 views

Best practice/design pattern for working with a config file

I am writing an application where a user will have a custom config json file. The json is just a dictionary where they define new objects of the exact same type. Here is an example with outfits: '...
Ryan Folks's user avatar
2 votes
2 answers
416 views

Process many types of work in parallel, but sequential for each type of work

Imagine there is a stream of requests for about 500 types of work. There can be say 5 workers in parallel. One type of work should be executed by at most one worker at the same time. The requests for ...
tm1701's user avatar
  • 89
0 votes
0 answers
108 views

How to handle Authorized & Non-Authorized Routes in Microservices with Tokens

Context Suppose there is a e-commerce microservice architecture with the format: In summary, a client will contact the Auth Service / Identity Service to receive a token. It passes the token to the ...
Gianluca Fuoco's user avatar
1 vote
2 answers
832 views

Software design patterns for versioning of domain entities/logic

I'm looking for specific software design patterns that can help me understand how versioning of the same entity where the domain logic has changed between the versions, can be solved. The following ...
martin's user avatar
  • 111
0 votes
1 answer
113 views

Data autonomy using files in a micro service application

We are rebuilding an on premise application using microservices and are wondering how to implement data autonomy given certain constraints that we are facing: The application is built around a set of ...
Q-bertsuit's user avatar
1 vote
2 answers
199 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 ...
Nishant Chauhan's user avatar
0 votes
1 answer
127 views

Best practices to link, associate, or abstract similar but different entities together

What are the best practices that I can follow that can simplify or help abstract out entity modeling when there are many similar but different entities? I have a large game system with different types ...
user21918's user avatar
  • 111
1 vote
1 answer
286 views

Self-Selecting Variant of the Strategy Pattern?

I've found this pattern useful, and am trying to classify or name it. Basically, that: A task should be performed by different strategies, depending on the context. Each concrete strategy implements ...
MrTrick's user avatar
  • 113
0 votes
2 answers
227 views

Architecture for worker pool with different task complexities and sizes of boxes

I'm sorry if I'm using any wrong terminology here. I'm trying to design an architecture where there can be big and small tasks (e.g. processing big or small images). Big tasks can only be handled by ...
nanotek's user avatar
  • 301
1 vote
1 answer
175 views

Using the decorator pattern to populate entity properties

I have products saved in my database that my system fetches with the following structure: public class OriginalProduct { public string Id { get; set; } public string Name { get;set; } } I need ...
filur's user avatar
  • 127
-1 votes
3 answers
735 views

Refactoring multiple non-nested if statements [C#]

I have a number of non-nested if statements that look like this: if (!bytes[nameof(PropertyVersion.Price)].SequenceEqual(dbBytes[nameof(PropertyVersion.Price)])) changes += $"Price {TextHelper....
Azhari's user avatar
  • 115
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 ...
Denis123's user avatar
-2 votes
2 answers
1k views

Are there more design patterns than the 23 of GoF?

We know the «Gangs of Four (GoF) Design Patterns» have 23 Design Patterns. But I wonder: are design patterns limited to these 23 or do we have more? And what would be the sources for other design ...
aircraft's user avatar
  • 119
-1 votes
1 answer
155 views

How to abstract version switching using feature flag?

I have two versions of an API with similar but slightly different response structure. We are currently using V1 of the API and will gradually move to V2 soon. The switch has to done using a feature ...
Hindol Dey's user avatar
0 votes
0 answers
41 views

Design pattern for scheduling method calls (open-loop control) [duplicate]

I have an ERP-style system that needs to allow users to orchestrate an Entity.action() on a variety of objects that implement the Entity interface, at different datetimes. Calling action() would ...
Escher's user avatar
  • 185
0 votes
2 answers
134 views

Multiple steps of mutations in one function - how to refactor?

My application contains webhook handlers that should execute many actions when the event happens. Given CUSTOMER_REGISTERED event this is what happens in pseudocode: function WebhookHandler(EVENT) { ...
filemono's user avatar
  • 103
0 votes
2 answers
1k 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 ...
charmoniumQ's user avatar
0 votes
1 answer
59 views

Use factory design pattern to create a specific object

I am using this DTO class to pass object between web application layers public class CreateProgressDTO { public int Total { get; set; } public int Created { get; set; } public decimal ...
dafie's user avatar
  • 109
2 votes
1 answer
66 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 ...
JaktensTid's user avatar
2 votes
2 answers
347 views

Design Pattern: How to handle changing format of text file?

I have a text file which is evolving and thus, difficult to manage. Hence, I am going to rewrite the code from scratch. Since, only few parts of the txt file change with a newer version, from the ...
Selva's user avatar
  • 129
0 votes
2 answers
203 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 ...
ParkCheolu's user avatar
2 votes
0 answers
74 views

Best approach for several steps with user input in between

I've read several questions and I couldn't find one specifically similar to mine. I also don't think there's a design pattern for this situation as I think my system is a legacy system and don't fit ...
Rick Wolff's user avatar
0 votes
2 answers
171 views

Refactor to object oriented style and use design patterns

I have an application that has been written in Python and it is used for generating various MIS reports for a specified month. It is now written without using the OOPs concepts or any kind of design ...
Happy Coder's user avatar
0 votes
2 answers
264 views

Coffee machine strategy pattern implementation

I came across an article about LSP https://stackify.com/solid-design-liskov-substitution-principle/ . It seems that a strategy pattern could be implemented here but I cannot see how to implement it. ...
Gullit's user avatar
  • 13
0 votes
1 answer
216 views

Where to create repository instances?

I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
Mr. B.'s user avatar
  • 143
0 votes
1 answer
94 views

Middleware with parameters and dependencies

I'm trying to use the middleware pattern to avoid repeating same code over and over again. In my application I work with user data a lot, therefore there are a lot of checks here and there. The ...
r32's user avatar
  • 3
0 votes
3 answers
495 views

Java Library - How to do Pure Dependency Injection When State is a Factor?

To set the stage, I am trying to do pure dependency injection for a Java Library I am creating to make it more testable. As it is a library, I want to do pure dependency injection without creating a ...
EspressoCoder's user avatar
1 vote
3 answers
563 views

Design pattern for feature toggling

To simplify the domain let's say we have a system that takes in orders from customers. There's an API endpoint that validates the input, and if valid pushes the order onto a messaging queue to be ...
Serberuss's user avatar
  • 139
0 votes
1 answer
102 views

am I understanding MVVM correctly? [duplicate]

ViewModel has Two-way data binding with UI which means UI can access the data from ViewModel and can update the view models data. The Model has one-way data binding and is only supposed to respond ...
Saketh's user avatar
  • 9
0 votes
0 answers
43 views

Pattern For A Load Behavior That Can Act On Any Class

I have a class called ContentLoader. This class has one method LoadContent<T>(T model, int?loadLogicDecider1, int? loadLogicDecider2, etc). It runs through the input class looking for a ...
Stevenfowler16's user avatar
-1 votes
2 answers
137 views

Appropriate design pattern for coupled Objects

I code an Object-Oriented simulation where you can have a Unit move on a Terrain. The cost of such move depends both on both Unit capabilities and Terrain features: a boat can move on water, a plane ...
Uriel's user avatar
  • 131
0 votes
3 answers
373 views

How to handle subclasses needing different method signatures for the overriden function?

I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, ...
Yoh's user avatar
  • 51
2 votes
1 answer
148 views

The notion of configurable strategies

I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore: The input is a scalar and a ...
Dev-iL's user avatar
  • 233
1 vote
2 answers
765 views

Modules Design and Communication Between Them

I'm trying to design a monolithic application following DDD and clean code. Lets say I have Users, User Types, Products, Product Types and Purchases. I want to implement using different modules. At ...
Amdguez's user avatar
  • 41
-2 votes
3 answers
223 views

Should I do dependency inversion on the same layer level

I'm working on an accounting service. I have to generate invoice for a user and upload it to the file storage. So my service would have to use a service from file storage team. File storage service ...
Patrick's user avatar
  • 173
0 votes
1 answer
776 views

How to share state between microservices

Consider a microservice architecture composed of a number of asynchronously communicating workers. Each worker deals with an isolated task and may have its own specialized database. Now consider that ...
carlo_barth's user avatar
9 votes
4 answers
2k views

UnsupportedOperationException vs Interface Segregation

This is a follow up/related question to a previous question I asked regarding Interface Segregation. I'll build up on the same example, providing a bit more context. In the game I'm developing, a card ...
Stefan Rendevski's user avatar
4 votes
3 answers
166 views

Simplifying TryGet methods to execute logic

Sorry my title is terrible i couldn't think of a concise title to use. I have a bit of code that needs to consume two quantities from two objects, this is done using a TryGet() type of method and the ...
WDUK's user avatar
  • 2,072
5 votes
1 answer
302 views

Does my View Model violate the Single Responsibility Principle? Or am I just used to toy examples from tutorials?

I am a very beginner writing one of my first webapps. I'm using FastAPI and I'm stuck on the logic of creating an endpoint that has to do a lot of things before it returns something back to the user. ...
Jinx's user avatar
  • 159

1 2 3
4
5
89