32,164 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
1
replies
45
views
What’s the best architecture for mixing local AI + cloud AI inside a React/JS app without turning the codebase into spaghetti?
I’m trying to design a “future-proof” React/JS setup where the app can switch between different AI backends (local models like WebGPU/WebLLM, API models like OpenAI/Gemini, and maybe even custom ...
Best practices
1
vote
2
replies
51
views
Finite State Machine for different enemies
I’d like to ask about best practices for using a finite state machine to handle different enemy behaviors.
I already created a state machine for my basic enemies with the following behavior:
...
Best practices
0
votes
1
replies
55
views
How to pass around scipy fit results and corresponding functions
I am looking for advice on how to best pass around the fit results from a (Python) script to another script.
Currently, I am exporting the best-fit parameters and function names into a YAML file. I ...
Best practices
3
votes
3
replies
69
views
How to avoid messy if statements when using many feature flags in Angular?
I’m part of a team of 10 developers, and recently our product team requires us to use feature flags for almost every new change.
The idea is that they can always “roll back” to the previous behavior ...
Best practices
0
votes
0
replies
49
views
Testing in MVVM architecture. What to test and how to approach TDD?
I’m currently working on a personal Android project using Kotlin and Android Studio, following a basic MVVM architecture:
─main
│ ├───java
│ │ └───com
│ │ └───example
│ │ └───...
Best practices
0
votes
3
replies
77
views
Can a Composite Component class inherit from another abstract base class without breaking the Composite pattern?
I’m studying and implementing the Composite design pattern in C# for a university project.
In most textbook examples (GoF, Refactoring.Guru, etc.) the class hierarchy looks like this:
Component
├── ...
1
vote
1
answer
86
views
What is the most Pythonic way to create a subclass of an object based on a string parameter
What is the best practice for creating an object based on the value of a string argument?
I am loading my configuration from a file and passing the string as an argument that gets mapped to a specific ...
Advice
0
votes
0
replies
32
views
Designing a props-driven test framework for data quality validation - best patterns?
Question: I'm building a testing system for a data quality SaaS app where tests are entirely props-driven (similar to React component testing philosophy).
Goal: Create reusable, composable test ...
Best practices
1
vote
2
replies
58
views
What is the best pattern for SwiftUI Document Application?
I am trying to create a full SwiftUI Document app (using swift 6, as it matters).
Apple doc says that the Document init(configuration:)and fileWrapper(configuration:)are called on a background thread -...
1
vote
0
answers
82
views
How to provide type-safe factory functions for dynamically registered classes in Python?
TL;DR
Suppose a Python library defines an interface meant to be implemented by third-party code. How could this library provide a factory function that creates instances of those implementations, with ...
0
votes
0
answers
82
views
How to register function delegate with interface that has a generic type?
I wanted to create a flexible MessageProcessor, depending on the SupplierType(= enum) and depending on which MessageProcessor comes out a different Message-object will be used.
The current situation ...
-1
votes
0
answers
162
views
Call a method of a class to destroy the object that is calling it
I'm developing a game with Unreal Engine 5.4.4 and C++ using Visual Studio 2022.
From a Character class I’m calling a GameMode’s method that will destroy this Character class that is calling the ...
Best practices
2
votes
4
replies
118
views
When is it OK to use a singleton?
Follow-up on this question: Singletons: good design or a crutch?
It is true, that using singletons can make testing harder, and bugs can hide behind them. GoF defines singleton to use when:
Global ...
Best practices
3
votes
1
replies
115
views
Architecture design for multilingual descriptions for several classes
I am creating an E-Commerce app. It has Category and Product classes. Both have multilingual descriptions, so, tables with title, description, meta-*, etc. and unique key (id, language_id).
To add ...
3
votes
1
answer
83
views
In Laravel’s Repository pattern, should I pass an Eloquent model (User $user) or a DTO to keep it framework-agnostic?
I’m refactoring my Laravel application to follow a clean architecture approach with clear separation of concerns:
Controller → Service → Repository
The Controller handles the HTTP layer,the Service ...
-1
votes
2
answers
159
views
C++ design pattern for connecting templated and non-templated classes efficiently
I complete the implementation of a VM (ALU part) by adding operations to a Coprocessor. In this sense, I'm looking for a C++ design.
Through a template, the VM is instantiated in 2 ways : A first ...
-1
votes
1
answer
67
views
SQLAlchemy session initialization in Command pattern [closed]
A question on consideration for case/approach choice.
Let's say we have an app that has an ORM model and also uses simple realisation of the Command pattern. Inside of each command we need to ...
-3
votes
1
answer
73
views
How do I implement multi-inheritance DUPLICATE method in Java?
I have an 8-level hierarchy of classes in Java. This is useful so each abstract class implements methods that are common in the whole sub-branch of the tree. That's working fine.
However, after going ...
0
votes
1
answer
157
views
Passing reference of this class instance in its constructor to other class instances
In Java, I can write something like this:
public class Brother {
private final Parent parent;
public Brother(Parent parent) {
this.parent = parent;
}
public void annoySister() {
...
0
votes
0
answers
45
views
Singleton pattern in Rust [duplicate]
Goal
Implement a Singleton Design Pattern for a struct, without multiprocessing considerations.
Minimal example
Here is the base of the code, without the singleton logic.
struct ...
2
votes
0
answers
225
views
Design dilemma with enum_dispatch in Rust
I'm designing my system which consists of three parts, abstract layer (al) where traits and generic data structures are defined; implementation layer (il) where different structures implement traits; ...
0
votes
0
answers
78
views
How to handle function order dependency (temporal coupling) between initialization functions without relying on comments?
I have two functions in my application startup sequence:
// Function A
async function loadPlugins() {
// loads plugin definitions
}
// Function B
async function createStoreInstance() {
const ...
5
votes
2
answers
201
views
Improve implementation of a "widget tree structure" in Qt6 [closed]
Let me introduce first the problem. I will present a simplification of my QT6 project app (in C++) to not make it too difficult to read, as the original code has lots of unnecesary things for this ...
0
votes
1
answer
103
views
Combining Windows' GetMessage Event Loop with a UI Animation Loop for Low CPU Usage [closed]
I am developing an app on Windows using the WinAPI. This app has a UI built using my own framework. Some views of this UI are animated and need to be refreshed over time.
Prior to implementing ...
1
vote
1
answer
108
views
How to return both early result and final async result using Promise?
When I make a POST request, the server responds immediately with an id, but the actual result is delivered later via a server push event (e.g., WebSocket or Pusher).
Here's what I'm trying to do:
When ...
5
votes
1
answer
226
views
Is there any reason to use virtual classes for factory method over map of functions in C++?
I'm implementing factory method for my polymorphic class.
The "traditional" way to do so would be to have two families of classes:
for objects themselves and for their factories.
In this ...
1
vote
1
answer
78
views
How to pass contextual data to a decorator without modifying the command interface?
I'm working on a feature where I need to send analytics data whenever a command is executed — for example, whether the command was triggered via a hotkey or a UI button. However, I want to achieve ...
0
votes
1
answer
77
views
Modeling a game convention set in Rust [closed]
I am writing a bot capable of playing a cooperative board game with other bots or human players.
In this game, there are black cards and white cards. Players can hold up to 5 cards in their hands.
The ...
0
votes
1
answer
86
views
How to implement a Multiton pattern with user-supplied factory methods?
I’m building a Rust library that manages multiton instances keyed by strings. Users of the library provide factory methods to create instances implementing a trait, and the library should:
Return the ...
-4
votes
1
answer
171
views
UML Class Diagram for a simple Unity System
I'm a bit rusty with UML and unsure if my class diagram effectively represents the architecture of my Unity system.
Goal: I'd like the diagram to clearly show how GUI elements get updated through a ...
0
votes
0
answers
120
views
Designing a Flexible FSM in Haskell with Typeclass States
I'm trying to build a simple Finite State Machine (FSM). Intuitively, I've described each finite state as a typeclass:
class FS st where
fsUpdate :: st -> StatefulEntity -> StateMondad st
...
1
vote
1
answer
153
views
Can template tag be inside template class itself?
I have a templated class Bounded which have parameters:
fundamental type
Min value allowed
Max value allowed
policy (wrap, limit)
I can do it if the struct defining policy is defined outside the ...
6
votes
2
answers
155
views
How can I generalize a unit conversion method for different Enums in Java?
I’m currently building a unit converter app in Java (as a beginner), and I want to avoid duplicating logic for each type of unit.
Right now, I have different enums like Length, Weight, Time, etc., and ...
0
votes
2
answers
86
views
Which design pattern can use for search overloading function? [closed]
In a interview, someone asked me this situation. How can you improve this.
search with many filter condition design pattern
Eg: let say search a gym by it distance, by its pincode, by its name, by its ...
4
votes
2
answers
99
views
How to pass values from application.properties to a java abstract class?
I'm new to Java class design and need help with the following:
Example scenario:
I want to pass the company name and email to the BaseEmailMessage class, and fetch these values from the application....
13
votes
0
answers
101
views
Are Mixins in C++ simply Policy-Oriented Design, or is there more to them?
Explanations of Mixins in a C++ context, but many of them seem to describe use cases that are essentially Policy-Oriented Design. This has led to some confusion on my part.
From what I understand, ...
1
vote
1
answer
100
views
How to properly reuse heavy calculations performed in the Parent class within the Child class?
Suppose I have a Parent class in Java:
public class Parent {
protected int value;
public Parent() {
value = performHeavyCalculations();
}
private int performHeavyCalculations(...
1
vote
1
answer
56
views
Handling Multi-Table Updates in Kafka
We have an application that serves as a configuration repository, storing data in a relational database. Whenever a user changes a configuration item, it is persisted to the database and our goal is ...
0
votes
1
answer
68
views
How can I maintain transactional integrity across distributed microservices using a hybrid event-driven and REST-based architecture?
I'm currently working with a distributed system composed of multiple microservices, some of which communicate via RESTful APIs and others through asynchronous messaging (Kafka).
My current challenge ...
1
vote
0
answers
72
views
Problems with complexity in dependency conditional injection with PHP-DI
I’m working on a PHP project where I’m using PHP-DI for dependency injection, but I’m struggling to configure a hierarchical structure of classes cleanly and scalably. I have interfaces like ...
0
votes
1
answer
160
views
Java does not allow using private final class member in lambda under certain pattern
A private lambda function is accessing a private final class member that is initialised in the class constructor. However, this code pattern compiles with error: variable num might not have been ...
0
votes
2
answers
75
views
Should custom Exception class contains business rules? [closed]
I have a question regarding whether exception classes should contain business rules, for example, supposing I have several exception methods, and in these exception methods I end up populating entity ...
-5
votes
1
answer
73
views
Confusion about EF Core intended work process
I have a simple form a user fills out. He selects some things from the DB like other users, etc, to fill in some entries, types other things manually, and submits it.
So I have a question: the docs ...
3
votes
2
answers
96
views
Dependency Injection Dealing with IDisposable
I am currently refactoring a legacy Job class to make it adapt to dependency injection pattern. However I have trouble managing the lifetime of IDisposable objects. It really get me stuck for a while, ...
0
votes
0
answers
71
views
Handling input requests in MVC pattern with an FSM
As a university software engineering project, my group has to make a videogame out of the board game Galaxy Truckers (rules summary, if it helps), using the MVC pattern (we're using Java as a language,...
0
votes
1
answer
192
views
Exposing actions in composable vs accepting reactive state to update internal state?
I'm starting to get comfortable with Vue's composition API, but every time I make a composable I ask myself which pattern to use. If I have a composable whose state depends on outside triggers:
...
1
vote
0
answers
129
views
Reading Health Connect Data Simultaneously Without App Pausing or Delay?
I'm developing a workout tracking app that integrates with Health Connect to collect and process sensor data during a workout session. The expected workflow is:
The user starts a workout.
Health ...
0
votes
1
answer
72
views
Rust observer pattern implementation with concrete data for each subscriber
I am working on a implementation of the observer design pattern where each observer is tied to a concrete type which should be received on notify. See the following minimal example:
Playground link
...
-2
votes
1
answer
121
views
Enum and Array vs Separate Variables to store multiple instances of a class [closed]
The following is a toy example:
An image stores a width, height and filepath, represented by the struct IMAGE:
#include <cstdlib>
#include <type_traits>
struct IMAGE {
int WIDTH;
...