Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,520 questions
0
votes
0
answers
25
views
Are there any good and modern approaches, to have variables that feel global (no need to pass them around explicitly), yet are local to an instance?
I'm developing a library in JavaScript (TypeScript, actually) which is split into several modules. It's meant to run both on the web and in non-web environments like Node.js.
The library is meant to ...
1
vote
4
answers
165
views
Is it good practice to return ApiResponse from a Spring service layer?
I'm working on a Spring Boot application with a VoucherService and VoucherController. I currently have the service method return an ApiResponse<T> directly, like this:
@Transactional
public ...
-3
votes
1
answer
184
views
Is there a name for this anti-pattern? (reference to a class member passed to another class method) [closed]
Is there a name for this anti-pattern?
A reference to a class member is being passed to another class method, rather than having the class method set the class member directly.
public class ...
2
votes
2
answers
304
views
How to design extensible data aggregation code to avoid manual updates in multiple places?
I have a data aggregation function that collects statistics from multiple sources. The problem is that whenever I add a new metric, I need to manually update the code in three different places, which ...
1
vote
1
answer
255
views
OO design - Process that relies on the current state of objects
We have a CAD software extension, where you can draw products like walls, doors, windows, etc., and you can export the drawing as an order, which contains the parts and costs.
As part of this export, ...
2
votes
7
answers
360
views
I'm looking for a design principle referring to using a system for it's intended purpose
Recently a junior team member was asked to use a survey tool to act as a system by which fuel delivery drivers could submit their Bill of Lading to our dispatch team for record collection after ...
0
votes
1
answer
95
views
Best practices for serving encrypted files in Laravel?
I'm building a Laravel-based web application that functions as a personal online photo archive. Each user uploads and manages their own private collection of images. These images are encrypted at rest ...
0
votes
6
answers
300
views
Design pattern for exposing different parts of interface to different entities
In a certain program I would like to have three objects, say, a, b, and c, with c being a shared private member (sub-object) of a and b. The data between the three objects shall only go this way:
a &...
0
votes
1
answer
158
views
Optimal way to avoid iterating through each row in a dictionary of data/arrays?
I have an excel macro that imports daily share price files, and finds the highest price for a share after a given date.
Each of these daily stock price files has ~1000 rows of data. Currently I have ...
1
vote
1
answer
155
views
Optimal way to match prioritized list of tasks with available workers
Problem
Match prioritized tasks with suitable workers.
Details
Consider a task with following properties - type and size. Based on task type, tasks are prioritized.
While a worker has following ...
0
votes
1
answer
95
views
Designing a Clean Separation for API Sorting Parameters and Database Columns
I'm working with a data mapper called UserMapper and a User model. Currently, UserMapper has a method called find_many. Now, a client makes requests like /api/users?sort_by=+last_name,-birthdate, so I'...
0
votes
1
answer
114
views
Designing a Scalable Caching Layer for User and Tenant Metadata in a Messaging System
I'm developing a microservice-based application that processes a high volume of messages. Each message must be handled according to the user’s personal settings and some tenant-specific (customer) ...
0
votes
2
answers
159
views
Is it better to pass a specific “context” object to handlers rather than the entire domain object?
I’m designing a system where various “handlers” apply business rules to an object. Initially I had each handler receive the full domain object:
// A large domain object with many properties and ...
0
votes
0
answers
76
views
When DI goes too deep - what is another architecture/design pattern you should use? [duplicate]
I like using dependency injection but sometimes I find that I have to nest some dependencies so deep that I would almost rather use a global variable (despite this being bad practice). Here is an ...
3
votes
3
answers
255
views
Is it good DDD practice to hide all the aggregate methods behind domain services?
I'm working on a DDD-based system and was researching the best way to handle domain services and keep business logic consistent.
During my research, I came across this insightful quote from Steve ...
3
votes
1
answer
194
views
How should User behaviour depending on role be design as OOP
Imagine I got user which might be either author, administrator, reviewer
An author have relation on book that he wrote.
An administrator have relation on banned user (we track which administrator ...
-1
votes
1
answer
328
views
Pattern for a chain of unreliable steps
I would like to refactor some code of a process that must perform a processing. The processing involves several steps, each of which can fail or go well. If successful, it must proceed to the next ...
2
votes
3
answers
168
views
Is this an aggregate in DDD? Is it unnecessary to group objects as an aggregate if there are no invariants?
Below is a scenario that needs to be modeled using the Domain-Driven Design (DDD) approach.
A Project can have Notes added to it.
A Note cannot exist without a Project.
A Note needs to be
viewable ...
4
votes
1
answer
206
views
Holding state in a service class in MVVM
In my SwiftUI app, I have a UpNextManager view model and a service class called UpNextService which contains many methods to read up next items from disk, write them to disk and much more. The service ...
3
votes
3
answers
495
views
Is it a good idea to wrap node.js package functions in a micro-service architecture?
Our development team works with a micro-service node.js architecture. This means we work with a very large amount of repositories that currently each take care of their own dependencies.
To avoid ...
3
votes
1
answer
169
views
Deciding on granularity of SOLID's SRP
I am currently working in a project where we are utilizing kafka as a Message Queue. We have two use cases here, one is to consume the messages in parallel, no ordering of any kind required. And one ...
4
votes
2
answers
723
views
why would one use the "Functional Options" pattern in go?
I just learned about the Functional Options pattern in golang.
what are the benefits of using it over just allowing to pass a config struct and just overriding the default values provided in the ...
3
votes
0
answers
264
views
How to encapsulate functions inside a library
I'm working on a project that uses an in-house library, which is also used by other projects.
There are some classes and methods in other classes that are not used outside the library itself, is there ...
1
vote
3
answers
315
views
How to handle authorization in CQRS
In a CQRS architecture, at least as implemented by Vaughn Vernon in IDDD_Samples, the query services lives in the application layer. But then where and how should authorization be handled?
For example,...
3
votes
3
answers
402
views
Repository returning multiple aggregates
A common DDD wisdom I encounter online is that your repository should not return more than one aggregate type.
But I came across this passage from Vaughn Vernon's book "Implementing Domain-Driven ...
3
votes
5
answers
1k
views
What is the design pattern of a program that uses global arrays to store variables?
Specifically, I mean code structured in a way where storage is global. Bare with me, as my terminology is all over the place. If I want to create a variable, I "load" it into a global cache. ...
0
votes
1
answer
249
views
What's the point of "use case optimal query" and partial aggregates in DDD?
In Vaughn Vernon's book "Implementing Domain-Driven Design", he talked about repositories that allows you to query for partial aggregates using a "use case optimal query":
(from ...
2
votes
3
answers
320
views
Aggregate with a huge list of value objects
I'm currently reading "Implementing Domain-Driven Design" while going through the code samples, but I'm having trouble modeling aggregates that stores a huge list of value objects. For ...
2
votes
3
answers
325
views
How do I model this scenario so that it adheres to OOP principles?
I have a Slide class with subclasses referring to the different types of slides (IntroSlide, SummarySlide, etc.):
abstract class Slide {
String slideType;
final String title;
final String ...
21
votes
5
answers
4k
views
How manage inventory discrepancies due to measurement errors in warehouse management systems
I'm developing an enterprise-grade warehouse management application for a chemistry laboratory. A critical feature involves mixing multiple stock solutions to create new solutions based on predefined ...
1
vote
3
answers
312
views
How to allow users to provide their own child classes in a factory design pattern in c++?
I am building a c++ project that will allow users to essentially model and create their own fleet of cars.
Right now, the approach I have in mind is a Car Factory Class that will implement all of the ...
2
votes
3
answers
1k
views
Is breaking encapsulation a necessary compromise for serialization?
I've been considering the way to solve this problem for a while, and I'm currently stuck between two options I both feel are suboptimal. Here's an abstract example of what I'm dealing with:
I have a ...
2
votes
3
answers
438
views
What is the relationship between the terms "association", "aggregation", and "composition"?
I try to brush up on my technical interview skills as I plan to seek a better offer
I don't recall being ever asked that really, but I still want to clear up any confusion. What is association, ...
-2
votes
1
answer
216
views
Best Practices for Managing Multiple Entity Types in ASP.NET Core
I'm working on an ASP.NET Core application that requires handling multiple types of a single entity. Each type has its own properties and validation rules, which has led to confusion and complexity in ...
0
votes
1
answer
260
views
Best approach to map user roles dynamically in ASP.NET Core Identity register method?
I'm working on an ASP.NET Core application that uses Identity for user management. I have an AccountService with a Register function, where I accept a RegisterBaseDto that contains the role ...
1
vote
2
answers
205
views
Decoupling UIs from Domain logics | Clean architecture
I've been reading articles on Hexagonal, Onion, Clean Architectures, and other Domain-Driven Designs. A common theme they emphasize is decoupling components. From what I gather, this means the UI ...
2
votes
3
answers
550
views
Implementing factory that return the correct type
Imagine I have a factory that must create object based on unknown input (let's say user input).
class Base;
class MyFactory {
static unique_ptr<Base> CreateBase(Input& input);
}
Now this ...
2
votes
3
answers
275
views
What options are there to handle dependencies that may error?
I have an application, which contains a logger. The logger already exists and is ready to be used, so it can be passed directly to the constructor.
class App {
private readonly logger: Logger;
...
1
vote
2
answers
698
views
What's the benefit of using Mediatr to handle Asp.Net requests?
I've just started in a new job and the company use Mediatr to handle all requests in their ASP.Net controllers.
I just can't see the benefit in using this pattern. I can see negatives but I'm ...
0
votes
2
answers
131
views
Aggregating classes to emulate multiple constructors using factory methods
I'm trying to make a utility Master class for aws client, and have mainly come across 2 types of commands/operations. Ones that require the S3Client, and others that do not. Therefore, I divided the ...
1
vote
0
answers
95
views
Deciding between two design alternatives for displaying series of screens in mobile applications?
I am developing a mobile application, and one of the features is a "story" that is essentially a series of screens. The screens can be of three main templates:
A "video" template ...
-2
votes
1
answer
237
views
Transaction Management Across Microservices with Rollback Mechanism using Kafka
I am currently developing a microservices architecture consisting of two services, and I'm facing a challenge related to transaction management and error handling.
Microservice A: This service is ...
0
votes
1
answer
253
views
Why is it called Data-Oriented Design?
I find the name data-oriented design very confusing - it sounds like data-driven development (letting hard data determine decisions in development) or data-driven programming (control flow determined ...
2
votes
4
answers
449
views
Builder with non-defaultable required args
Suppose a class needs multiple properties of the same type. I don't want a big constructor where the user can mess up the order of args (remember, they are of the same type, no compile-time errors)
...
1
vote
1
answer
402
views
What does it mean to be "truly" asynchronous?
Reading the Proactor pattern paper, specifically this part:
I/O Completion Ports in Windows NT: The Windows NT operating system implements the Proactor pattern. Various Asynchronous Operations such ...
3
votes
6
answers
615
views
Trying to write a sane alternative to the visitor pattern, please help me review it
EDIT: This post has a single question but a lot of context. The single question is if there are downsides with the approach I'm taking over the common Visitor pattern.
I've been thinking about the way ...
5
votes
1
answer
337
views
What do you call an enum that translates its own values?
I see this pattern a lot, especially with countries, or more generally regions. An enum is defined with additional fields and with methods that translate to and from these values.
Example:
import ...
1
vote
1
answer
316
views
What are the common design patterns for updating user data of a desktop/mobile application?
Question:
What are common architecture patterns/strategies of updating user data (think of XML/Json/sqlite/custom binary format) when the format of the data needs to be changed, and when that change ...
3
votes
5
answers
812
views
Why is "dependency injection" ok, but not "the opposite of preserve whole object (pass required parameters only)"?
According to Why should I use dependency injection?, "dependency injection" has some advantages, for example:
"Non dependency injection" version:
public class Client{
private ...
2
votes
1
answer
174
views
Should I create another API to “move” content or modify my existing API that already does something similar?
I have a Spring Boot REST API that will copy content from one Amazon S3 bucket to another. The source and destination buckets are specified in the body of a POST request sent to the API. This works ...