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
5 votes
2 answers
457 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 ...
  • 393
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
86 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 ...
-2 votes
1 answer
344 views

Is this the right mechanism for 2 way heartbeat?

I have a software application where we have 2 services, say A and B. A delegates some long running work(tracked by an id) to B which is done asynchronously. They both talk via HTTP. Post submitting ...
0 votes
3 answers
131 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
58 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
211 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 ...
  • 327
0 votes
2 answers
170 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 ...
  • 329
1 vote
1 answer
430 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 ...
  • 19
0 votes
1 answer
66 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 ...
  • 101
2 votes
1 answer
95 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
815 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
92 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, ...
  • 101
0 votes
1 answer
196 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 ...
  • 1,894
2 votes
2 answers
317 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
449 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
89 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
45 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
270 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
-1 votes
1 answer
169 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 ...
  • 99
0 votes
0 answers
73 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
212 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
284 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 ...
1 vote
0 answers
96 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
189 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 ...
  • 203
1 vote
2 answers
269 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 ...
  • 119
5 votes
2 answers
638 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 ...
  • 59
2 votes
2 answers
230 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
939 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 ...
  • 119
-2 votes
1 answer
93 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 ...
  • 11
2 votes
2 answers
399 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 ...
  • 172
2 votes
2 answers
234 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) ...
  • 137
0 votes
2 answers
102 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 ...
  • 109
1 vote
3 answers
292 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 ...
31 votes
9 answers
7k views

Is extracting an interface just for testing purposes a code smell?

I will explain with an hypothetical example. Suppose that my domain is Cars. Everyone around the software, talks about cars. Car is the aggregate root of aggregate roots. For example, CAR table has ...
  • 705
1 vote
2 answers
152 views

Maintainably converting flowchart ideas to an architecture

My team is communicating proposals for the interaction of several processes as a flowchart. I've been drafting a codebase architecture we can use as a starting point. There are two ways intended ...
  • 325
0 votes
2 answers
389 views

Dealing with multiple application instances

I'm developing an application (Java & JavaFX) that writes/reads data (a file). The problem is I don't want to restrict user to run only one instance (of my app) at a time, as I really can't think ...
  • 43
0 votes
1 answer
56 views

Design a non replayable endpoint for a service

I am trying something out in Springboot and stuck with a weird issue where I want to send some data from my frontend (react app) to backend (SpringBoot) and make that request non replay able by users (...
-2 votes
2 answers
61 views

When to self-audit complex calculation [closed]

Given an app that manages appointment bookings, I'm separately storing purchases, bookings made, or cancellations (some of them non-refundable) and am required to show the sum of these, based on ...
  • 105
2 votes
2 answers
210 views

Should you create your own Interface for all (most/many) Api Calls? (Adapter)

I am currently reading Clean Code by Robert C. Martin and in Chapter 8: Boundaries one can find this paragraph: We wanted to tell the transmitter something like this: Key the transmitter on the ...
  • 249
3 votes
5 answers
290 views

Add specific behavior inside classes

I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
3 votes
2 answers
391 views

Design of a modular application

I'm developing an application (Java) in a modular architecture. I have two approaches in mind and I'm not sure which one will be "better code" in case of maintenance and conventions. I have ...
1 vote
0 answers
164 views

What design pattern does this implementation follow?

For a middleware solution I expose an API, which processes data and sends the necessary information to different parties. In the current design we create a new client, which acts sort of like an ...
5 votes
2 answers
297 views

Permission Design - Allow/Deny vs Allow Only

I've come onto a new a project and the permissions are done with an allow and a deny option for every permission. Until now i've only ever seen/build allow only permissions. What is the advantage of ...
  • 375
2 votes
2 answers
334 views

How to handle duplicate null checks

I'm working with a legacy codebase that has a lot of functions with a nullcheck on the same object. Example: std::vector<SessionNode*> * SessionManager::SessionMap; Session * getSession(int ...
2 votes
3 answers
220 views

Use abstract factory (or an alternative way) to produce an instance of a subclass?

Context for this question I'm currently working with small data storage media (e.g. RFID tags) that contain some fixed number of bytes that can be manipulated. The drivers that allow reading bytes ...
1 vote
3 answers
172 views

How to design a function with different output formats

I often have to write a function which may return an output of two kinds: "short" and "long". As an example, consider the subset sum problem: the input is a set of integers S and ...
1 vote
1 answer
264 views

Builder design pattern when creating object between many layers

I stumbled on following problem, and I'm curious if it could be done better. A while ago I wrote a factory class that looked something like this: public class Foo { private IDbContext ...
-2 votes
1 answer
104 views

What is a right way to handle requests?

A social network has API, but also it has some limitations like the amount of requests that can be done in one second (let's say API will give an error, if it accepts more than 3 requests per second) ...
4 votes
1 answer
178 views

How can I create a workflow for physical unit safety in Python?

I work for an engineering firm which builds most of our physics models in Excel with VBA. For myself and many other younger mechanical engineers in the company, this is not a good solution - we grew ...

1 2
3
4 5
87