Questions tagged [design-patterns]
A design pattern is a general reusable solution to a commonly occurring problem in software design.
4,519 questions
3
votes
1
answer
2k
views
Specification pattern and maintaining domain logic inside entity
I would like to know more about the Specification Pattern, as it is described in Eric Evan's book "Domain Driven Design".
One of the key points Evans makes is that the domain model contains ...
1
vote
1
answer
261
views
Are there any drawbacks to partial application?
Consider the following Typescript code:
function exampleAction(target: Target, options: ExampleActionOptions) {
// ...
}
export function getExampleAction(options: ExampleActionOptions) {
return (...
1
vote
1
answer
260
views
Refactoring instanceOf, moving logic to POJO when it has database interaction
I'm refactoring some old code, I have a lot of istanceOf in the business part:
if (record instanceof RecordA) {
RecordA recordA = (RecordA) record;
...
2
votes
2
answers
663
views
Replacing the Decorator design pattern with a list of methods
So I've been going over some design patterns and I came across this discussion
https://stackoverflow.com/questions/43565475/using-lists-instead-of-decorator-pattern
I've been thinking that in all ...
-1
votes
1
answer
237
views
How can I use builders for products with incompatible interfaces?
I am working on a program to automatically design heater units based on varying client specifications.
The process for creating each heater is quite involved and requires multiple optional steps ...
-1
votes
1
answer
105
views
How to solve inter-dependency of the composed class on it's property
In one of the project I am working on, I am facing a problem in terms of creating an object with a dependency that sits at a deeper level in the class composition. Following diagram shows the class ...
3
votes
3
answers
667
views
Definition of "collaborators" (of an object) in Software Design?
I have seen Martin Fowler using the term "collaborators" as some sort of synonym of "dependencies". Unfortunately, Martin Fowler does not seem to define the term anywhere, so it is ...
0
votes
2
answers
796
views
How to create an interface in C that can work on two identical structs with differently named fields
Question Background
Consider a scenario in which I have two structs. Both consist of three fields for doubles. The only difference is the names used to refer to these fields. The first struct is for ...
0
votes
0
answers
149
views
Python Typechecking versus TypedDicts?
From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function:
def some_func(some_int: int, some_dict:...
0
votes
3
answers
2k
views
Best way to provide default objects from a simple class in C#
I have a Material class :
public class Material
{
public string Name { get; private set; }
public double Density { get; private set; }
public double SpecificHeat { get; private set; }
...
2
votes
1
answer
3k
views
DDD: Can application services throw domain errors?
I'm new to DDD and I trying to create an API using DDD concepts for study purposes. Today, I faced a scenario where I've to create an Application Service to expose a functionality to be cosumed from ...
3
votes
1
answer
191
views
Should I have different instances of the same model in an application or just keep a single instance?
What is correct in your opinion regarding the creation and handling of models in an application let's say using MVVM, or even an MVC design pattern?
I will try to illustrate the situation I see at my ...
1
vote
2
answers
261
views
physical simulation: design thoughts
I'm an applied physics student and currently working on a simulation of the magnetic interactions of multiple protons within a protein.
Me having only little experience with programming and almost ...
-2
votes
1
answer
81
views
Pattern for flexible promotions/badges [closed]
Let’s imagine system like Garmin connect, you run, record your workout and then once you finish workout is uploaded to the system and being analyzed. Based on analysis you can receive badge: for 5 km ...
0
votes
1
answer
168
views
C# Best Practice DI Pattern?
Is there a best-practice pattern I can/should use for this scenario? I need access to some DI services in the OnFinished() method:
public class Product
{
public int Quantity {get;set;}
}
public ...
0
votes
1
answer
462
views
Where should I create my aggregate root? in api or frontend?
I am writing a simple application to apply what I have learned so far in DDD.
I have the following mysql tables in my api server
Sales
Column
id
pk, int
title
varchar
description
varchar
Images
Column
...
0
votes
1
answer
524
views
Multiple models/controllers python app
I am trying to tinker with the MVC pattern and I have a problem when trying to design the MVC structure. I need a model for products, however as I need to manage more and different data, I can help ...
0
votes
1
answer
1k
views
What design pattern / solution helps me elegantly map classes that share the same base class
I'm looking for an elegant way (a design pattern if such exists, not a library) to map two classes that share the same base class, without duplicating the code that maps the properties of the base ...
1
vote
1
answer
4k
views
Return type specification if a Python function output type, is dependent on the input arguments of that function?
Context
Suppose one has a list of algorithms, which each have a multiple run/parameter configurations. Next, one wrote a generic function def get_mdsa_configs(self) -> List[MDSA_config]: that ...
3
votes
2
answers
619
views
Process many types of work in parallel, but sequential for each type of work
Imagine there is a stream of requests for about 500 types of work. There can be say 5 workers in parallel. One type of work should be executed by at most one worker at the same time. The requests for ...
1
vote
2
answers
2k
views
Software design patterns for versioning of domain entities/logic
I'm looking for specific software design patterns that can help me understand how versioning of the same entity where the domain logic has changed between the versions, can be solved. The following ...
1
vote
2
answers
222
views
Why do we separate interface when implementing interface injection variant of DI?
With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase.
public interface ServiceSetter {
public void setService(Service service);
}
Why ...
1
vote
1
answer
420
views
Self-Selecting Variant of the Strategy Pattern?
I've found this pattern useful, and am trying to classify or name it.
Basically, that:
A task should be performed by different strategies, depending on the context.
Each concrete strategy implements ...
1
vote
1
answer
218
views
Using the decorator pattern to populate entity properties
I have products saved in my database that my system fetches with the following structure:
public class OriginalProduct {
public string Id { get; set; }
public string Name { get;set; }
}
I need ...
6
votes
6
answers
557
views
Best practice to architect a system in which local users may override global definitions
Our travel industry client, operating across three continents and several countries, wants to standardize the process of choosing travel packages, air routes, hotels, and hundreds of other travel ...