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
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 ...
user avatar
-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 ...
user avatar
-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 ...
user avatar
  • 115
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, ...
user avatar
  • 23
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 ...
user avatar
  • 223
-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, ...
user avatar
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 ...
user avatar
  • 31
-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 ...
user avatar
  • 123
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 2,000
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. ...
user avatar
  • 149
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: ...
user avatar
  • 33
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 ...
user avatar
-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 ...
user avatar
  • 179
-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 ...
user avatar
  • 29
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 ...
user avatar
  • 373
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 ...
user avatar
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 ...
user avatar
-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?
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 327
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 ...
user avatar
  • 329
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 ...
user avatar
  • 19
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 ...
user avatar
  • 101
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 ...
user avatar
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 ...
user avatar
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, ...
user avatar
  • 101
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 ...
user avatar
  • 1,884
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
-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 ...
user avatar
  • 1
-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 ...
user avatar
  • 99
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 175
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 ...
user avatar
  • 109
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 ...
user avatar
  • 29
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 ...
user avatar
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 ...
user avatar
  • 119
-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 ...
user avatar
  • 11
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 ...
user avatar
  • 172
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) ...
user avatar
  • 137
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 ...
user avatar
  • 109
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 ...
user avatar

1
2 3 4 5
86