Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,241
questions
0
votes
0
answers
10
views
How to design multi module spring boot application
i'm developing a multi-module spring boot application, the basic idea would be to have an application divided into several modules, where there is a common module that imports one module or another ...
0
votes
0
answers
13
views
Observing changes in repository
I am developing a messaging application for iOS (although my question is not iOS related).
I am using offline-first approach and I am adhering to the clean architecture design pattern.
I currently ...
0
votes
1
answer
51
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
0
answers
60
views
When, and why, to pass parameters by value? [closed]
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 ...
-1
votes
0
answers
32
views
Alternative design pattern to a method containing a lot of methods? [duplicate]
I have a method in a class that takes in some variables and then runs a series of other methods in a pre-defined sequence. Below is a simplistic example:
class MyClass:
def ...
0
votes
1
answer
59
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 ...
1
vote
2
answers
66
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
35
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
82
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
70
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
71
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 ...
0
votes
1
answer
86
views
Plugin architecture vs Interface Segragation Principle (SOLID) [closed]
Uncle Bob's Interface Segragation Principle (ISP) tells us that many client-specific interfaces are better than one general-purpose interface. But plugin architecture in common case suppose to have ...
-3
votes
0
answers
70
views
Utilizing OOP principles effectively to implement a graph algorithms demo application
I am currently working on writing a C++ app whose purpose it is to essentially "demo" various graph algorithms. At the moment, I have a very bare-bones Graph class working (which utilizes ...
1
vote
1
answer
58
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
132
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
51
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
156
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
203
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
120
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
169
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
126
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
80
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
318
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
227
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
66
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
96
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 ...
0
votes
2
answers
122
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 ...
0
votes
1
answer
106
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 ...
0
votes
1
answer
49
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
56
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 ...
2
votes
2
answers
143
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 ...
3
votes
5
answers
274
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 ...
2
votes
2
answers
264
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
134
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
225
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 ...
2
votes
2
answers
302
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
151
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
162
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
116
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
80
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)
...
3
votes
1
answer
160
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
vote
1
answer
114
views
Common methods of generating code with code
I wish to develop an application that can generate code based on an user input.
Long story short: a user gives a formal description of a Resource (can be viewed as a REST resource) and based on this ...
0
votes
4
answers
145
views
Adapter or pure interfaces?
I got a bit strange 'future ready' scenario. And I'm not sure if I got it right in regards to C# adapter design pattern.
The scenario is that to be future ready, 'to use the adapter pattern' to easily ...
2
votes
2
answers
91
views
Design pattern to create a shared lib architecture
I am making a renderer as a hobby, one thing I thought to try is making the low levelAPI be dynamically swappable, i.e. you could have an opengl or vulkan backend and switch between the two without ...
2
votes
4
answers
229
views
What is the middle ground between understanding basic OOP concepts (inheritance, composition, aggregation) and design/architectural patterns?
I've been coding in python for about 6 years now. I am proficient enough to understand a good amount of the language features. When I look into source code for a number of libraries such as pandas or ...
-1
votes
2
answers
114
views
Is having a big class always considered bad OOP design? [closed]
So I have this distributed game im working on(for some time now). A part of the world is considered a Chunk object. This object is composed of many other objects/components that are necessary and a ...
0
votes
3
answers
112
views
Composite Pattern get part of the tree
I use java and I have structure with a class that contains id, title and perhaps some children of the same class. So I decided to use the composite pattern.
I need to have a method getChildren() that ...
2
votes
1
answer
129
views
Delegating whole class bad practice?
Suppose I have the following struct:
struct Dimension
{
void setDimension(Vector2i dim);
Vector2i getDimension() const;
bool canShowInformation();
}
And this struct uses the Dimension ...
1
vote
1
answer
72
views
Hierarchical State Machines - Ortho Regions
I am rather unclear about how an event gets processed when a state machine has orthogonal regions. I did read that
With composite states, that an event should be sent to the innermost state, and if ...