Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,259
questions
0
votes
0
answers
29
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 ...
-2
votes
0
answers
86
views
How might you go about reversing the direction of a compiler? [closed]
This is a kind of "inverse problem"
WE HAVE
WE WANT
A compiler A which translates LaTeX into "naïve math"
A compiler B which translates "naïve math" into LaTeX
There ...
-1
votes
0
answers
49
views
Appropriate design pattern for coupled Objects [closed]
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 ...
0
votes
3
answers
166
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, ...
1
vote
1
answer
110
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 ...
-3
votes
0
answers
82
views
Using a hybrid watermarking/fingerprinting approach for identifying GPS geolocation data [closed]
Our backend is made up of thousands of micro-services. My team deals with and owns geolocation data for our entire backend ecosystem. We get different types of geolocation data from customers: GPS, ...
1
vote
2
answers
58
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 ...
-2
votes
3
answers
108
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 ...
0
votes
1
answer
132
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 ...
8
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 ...
3
votes
3
answers
137
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 ...
4
votes
1
answer
197
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. ...
0
votes
1
answer
75
views
Should I keep the structure of the API request body same in all cases?
I have Items and Im creating an API which validates different aspects of an Item. eg: whether it has a valid height, width or depth.
My request body looks like
{
height_check: true,
width_check: ...
0
votes
1
answer
62
views
I don't understand how to characterize a class similar to a DTO but with validation
I have the entity class.
@Entity
public class User {
@Id
@GeneratedValue
private long id;
private String name;
private String lastname;
@Column(unique = true)
private ...
-1
votes
1
answer
48
views
Any pattern for delaying processing of a (JMS) message until another task completes
Is there a good pattern in microservices systems for delaying the processing of a JMS message until some other task has been completed. Let's say, for example, a message is sent to a topic when a ...
-1
votes
2
answers
242
views
Is it bad practice to have too many direct subclasses?
Let's say we have an undo/redo system and we have a superclass storing an object that should later form a tree of the attributes that can be undone/redone.
This would require every class that should ...
4
votes
2
answers
260
views
How to organize a chain of functions that share parameters, functional programming
When trying to follow a functional programming paradigm, I often find myself in a situation where I have a chain of functions that I would want to combine/compose somehow, but they all also take in a ...
5
votes
3
answers
2k
views
Looking for the name for an abstract class that models functions as objects
In mathematics, adding two functions can be considered an operation in the space of functions. The result is another function.
I can model this by making functions an abstract class and implement all ...
0
votes
0
answers
74
views
Identify Domain Entities for a search tool interface - Clean Architecture
I am pretty new to Clean Architecture / Onion Achitecture, I actually not sure if the 2 terms are exchangeable.
So it pretty clear to me, considering is a few days I am reading and study about it.
It ...
-3
votes
1
answer
233
views
Is this the right mechanism for 2 way heartbeat?
What is the right way to do it for a service runing on 2 places?
0
votes
3
answers
90
views
Decoupling command and receiver in command pattern
I'm writing a simulation of a car that can receive commands and act on them and I'm trying to implement it using the command pattern.
class Car {
move() {
console.log('move');
}
}
interface ...
0
votes
0
answers
49
views
parent-child properties value inheritance at runtime/instance
I have 2 entities with a parent-child relation (like a base product and product variants), basically the two entities have the same properties and at runtime (when instantiating the object) if the the ...
0
votes
3
answers
198
views
If I have a ThingFactory which creates multiple concrete IThings, each with exclusive parameters, how do I avoid ThingFactory knowing about them all?
A common problem I run into is when I have a Factory (let's say ThingFactory) which creates multiple different IThing implementations, and each of these concrete implementation classes requires an ...
0
votes
2
answers
89
views
Should I instantiate the state objects of a finite state machine?
I have a class hierarchy with a base State class, several inheriting classes each named after their relevant state, and an FSM class that contains all the states in a particular state machine as well ...
1
vote
1
answer
250
views
How to avoid argument drilling when subdividing functions?
As suggested by Uncle Bob in his book "Clean Code", I am actively trying to keep my functions small and readable.
However, I often encounter arguments drilling when I try to refractor a big ...
0
votes
1
answer
62
views
Good approach to design Business interface for versioned API?
I am designing an API using .NET core 6 C# which has 2 versions. For v1 I have something like the following for the business logic interface (fictional names and simple fields just to facilitate ...
1
vote
1
answer
55
views
How would you implement a execution graph like dependency for python scrips?
I am often confronted to this problem in my scripts and I feel I am lacking some software design culture, I hope this is the right place to ask and sorry if this sounds too simple.
I write many ...
0
votes
4
answers
151
views
Design REST Polymorphic API
I have a client/server application that exposes data and commands through REST APIs. This API exposes a GET /recipes/:id endpoint that instructs the client on how to show a recipe. A recipe can be ...
0
votes
0
answers
62
views
Querying data from multiple microservices
I'm trying to design an application that uses the microservices architecture. The service would have an api gateway, a user service and then a seperate service for each analytic source.
For example, ...
0
votes
1
answer
110
views
Does every Visited class have to be aware of the Visitor interface?
I'm taking another look at the pros and cons of the Visitor design pattern for a talk.
There's obviously the issue that the Visitor has to be aware of every class it has specific handling for, but ...
2
votes
2
answers
256
views
When, and why, to pass parameters by value?
For anything larger than a 64 bit integer, why would I want to pass by value?
[Update] The question was closed, because it was not specific enough. One comment suggested that I specify a language. I ...
0
votes
1
answer
104
views
is there a two-way (bidirectional) observer pattern?
I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each ...
2
votes
2
answers
77
views
Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?
I work in a production company where my colleagues calculate costprices based on 3D models and their respective operations. Apart from workactivities where a user has to insert an operation time and ...
0
votes
0
answers
44
views
Refactor conditional multiple AND OR operations? [duplicate]
I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions.
So the first method is as below where I check whether the profile ...
-1
votes
1
answer
94
views
State machine using SOLID principles. Connecting to real devices
I am trying to implement code for switching states of a couple laboratory devices. My considerations are: how should I link the state objects, state machine object and device manager object to follow ...
-1
votes
1
answer
92
views
How to apply the Open-Closed design principle for different parameters in each class
I am a noob in design principles and design patterns, this might seem like a very silly question.
Some classes in my code have the following structure (image linked):
https://ibb.co/nrp1t2g
As you can ...
0
votes
0
answers
72
views
Replacing TLD in image urls without changing the data
I have a flutter app which uses firebase/gcp as a backend.
Files can be uploaded and stored on google cloud storage.
In flutter I am using an UploadImage and UploadVideo model to store information ...
1
vote
1
answer
85
views
How can one combine two system architectures, say client-server and repository architecture?
I have a situation where I think it would be best to combine two architectures but I am not sure if this is possible or that it is a good thing to do.
By combining them I mean taking certain parts of ...
0
votes
2
answers
156
views
Best pattern/practice to execute a multi-step code generation process
I am working on a project that generates an API with the possibility of doing CRUD operations based on a high-level description of the resources that the user would like to have in an application. In ...
0
votes
0
answers
62
views
Splitting an object's state into multiple objects
I'm writing a virtual CPU, and I decided to create a class for each command, to make it easier to replace/add/remove commands without changing too much.
The original idea was that ICommand would be ...
1
vote
4
answers
163
views
Modelling interactions (Domain driven design)
To use a dumb example, assume that particular users (labourers) can move boxes around. How would you go about representing that in your system in a semantic way that scales. I'm currently inclined to ...
0
votes
2
answers
215
views
Which strategy to use to create object instances
I have this use case (I've simplified it):
Each student can apply for one or multiple activities. As of now we only have Swimming activity onboarded on the system, but we expect to have more. Base ...
2
votes
1
answer
182
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 ...
2
votes
1
answer
175
views
What is the best way to compartmentalize complex logic problems?
I am working on a problem with lots of if-then-else calculations. I am trying to compartmentalize the logic to make it more maintainable and less error prone. But, as I try options, I don't see what ...
1
vote
2
answers
310
views
Difference between Strategy pattern and Repository pattern
I found the following definition of Repository Pattern:
Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access ...
-2
votes
1
answer
83
views
Are there real examples of using reflection design pattern to achieve partial deployment? [closed]
This site mentions such thing: http://software-pattern.org/Reflection. It says that it is possible to replace part of the application behaviour dynamically. Does it mean that we can achieve partial ...
2
votes
2
answers
351
views
The motivation behind the Factory Method design pattern
I'm learning about the Factory Method Desing Pattern and I'm having a hard time to understand exactly what it tries to solve and how.
Let's first introduce the example that Wikipedia uses to have a ...
2
votes
2
answers
231
views
"Returns true if changed" pattern [closed]
The Collection interface in Java has, among others, these methods:
boolean add(E e)
boolean addAll(Collection<? extends E> c)
boolean remove(Object o)
boolean removeAll(Collection<?> c)
...
0
votes
2
answers
70
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 ...
1
vote
3
answers
123
views
Storing count of child rows in parent table
I have two tables, parent and child. Parents can "have" multiple children—in our case they are related through a third table, parent_child_mapping rather than the child storing its parent id ...