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
1 answer
130 views

How do we nest decorators?

It is possible to nest many decorators. @decorator_one @decorator_two @decorator_three @decorator_four def some_silly_function(): pass How do we write a decorator class so that the order in which ...
0 votes
0 answers
40 views

Combining Strategy and Decorator pattern (see GOF) to Spectrogram computation

I'm trying to design and develop a software (part of a bigger application) that should compute and render a spectrogram. The spectrogram can be rendered either from live microphone or a file (assuming ...
1 vote
0 answers
72 views

Limiting exposed interface for state transitions

Scenario: Given a class with some internal state and methods to manipulate this state, I want to limit the exposed methods that are available to potential clients/users of my API. TLDR: In the ...
  • 333
1 vote
1 answer
75 views

Composite repositories: minimizing dependency injections

I have an application with dependency injection that consumes a REST API. The API calls are abstracted into entity-specific repositories. Some of the repositories are: HttpNotebookRepository, ...
  • 91
3 votes
2 answers
212 views

Creating an abstraction just for exception handling - a pattern or anti-pattern?

Assume that an external library or framework not under our control exposes a Controller API: abstract class Controller { abstract fun call(): Result } Assume that we want to handle exceptions ...
-1 votes
1 answer
39 views

How to handle dependencies between objects/components

Im currently working on a college project on the simulation of magnetic interactions of particles, see physical simulation: design thoughts. Right now im starting to code my system according to this ...
  • 27
-1 votes
1 answer
78 views

How can I prevent an object from being re-sanitized everytime it is passed as input to a function?

Suppose that I have a class named CharStream Additionally, there are a large number of functions which convert their function input into a CharStream def funky_the_function(_input): input = ...
-2 votes
0 answers
27 views

Design pattern and middleware solution [duplicate]

I am a junior developper using Intersystem Ensemble in my job and i'm wondering how does design pattern relate to that kind of software ? For exemple, i've been given the following task : Check for a ...
  • 1
-2 votes
0 answers
62 views

Design Pattern for a showroom project

Good morning everyone I am doing my first real software engineering project and have been given the task of determining whether it is possible to use Design Patterns for our project. Context: The team ...
2 votes
2 answers
104 views

Pattern for a base class to do pre-validation and/or post-processing on a deriving class's overridden method?

I have the following pattern repeating itself in multiple places: abstract class Database { void connect() { this.setStatus( CONNECTING ) try { await this.realConnect() } catch ...
2 votes
3 answers
211 views

Method that returns an object is it adequate for TDD?

Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object. It starts to get really complex in my opinion and doesn't ...
  • 147
1 vote
1 answer
141 views

Storing multiple instances on a Singleton?

RefactoringGuru's example Singleton in Python has an _instances dictionary field class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls....
1 vote
3 answers
170 views

Is in my case role based access better than permissions?

Hello StackExchange community, I'm in a bit of an impasse for my current project. The software in question is a collaborative program designed to let employees work together on the platform and assign ...
1 vote
1 answer
85 views

Is it an acceptable pattern to put derived classes inside an abstract base class in Java?

Suppose I have some Java code such as the following (in this case, the use of the name "interaction" is referring to interacting with an object in a video game): public abstract class ...
0 votes
0 answers
62 views

REST API design - Categorised response objects - All, Sub, Dub movies paged response

I am having trouble deciding what is the best way to implement a REST API which does the following: When page gets loaded, it displays a list of Movies and above is a category selector tab (ALL, SUB, ...
  • 1
1 vote
1 answer
164 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 ...
0 votes
1 answer
81 views

How to refactor parallel inheritance tree?

I have a (php) program, which must change yearly. This program calculates tax for every year and there are sometime changes in requirements. First, the user fills their incomes, expenses, etc. Then ...
  • 111
0 votes
1 answer
118 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 (...
  • 155
1 vote
4 answers
231 views

Most efficient way to represent a random ordering of the numbers 0-10

I am currently looking for a way to encode a list of random numbers most efficently (as in length). To be specific, I have an array of 11 numbers containing each number from 0 to 10. The order will be ...
  • 29
1 vote
1 answer
73 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
100 views

Designing Products with multiple variations

I have a Product entity: public class Product { public int Id { get; set; } public string? Name { get; set; } public string? Description { get; set; } [ForeignKey("Brand"...
2 votes
2 answers
200 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 ...
  • 129
1 vote
1 answer
107 views

How to implement converters without needing to implement every permutation

I've got this class: [UsedImplicitly] public class ClassicalKeplerian { public ClassicalKeplerian(Angle argumentOfPeriapsis, Angle inclination, UnitFraction eccentricity, Angle ...
1 vote
0 answers
43 views

API contract design for field attribution based schema

I am currently working on a problem which involves defining the API contract (or DTO/Schema). Note that this will be private API, and non public. The following image shows a possible form of the ...
1 vote
1 answer
109 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 ...
3 votes
1 answer
125 views

Design for the future or make it tightly coupled to the implementation

My question is regarding how would the developer know when you add interfaces/protocols to their code and inject them as dependency. Consider an example of BudgetService. protocol ...
  • 141
0 votes
1 answer
78 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 ...
  • 9
-1 votes
1 answer
77 views

CRUD for hierarchical data in ASP.NET - single view/controller vs. separate view/controllers?

I'm trying to develop a CRUD feature for an ASP.NET app that lets me manage customer information. Each customer can be subscribed to one or more services, and each service can have one or more terms. ...
  • 7
3 votes
3 answers
271 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 ...
  • 31.9k
1 vote
1 answer
112 views

Exposing only the getters of a singleton interface in C++

I've got a file in my includes folder, which is the folder I expose, that isn't used externally and isn't supposed to be used too. When I noticed that and tried to remove it - I noticed that it's ...
  • 113
1 vote
2 answers
153 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 ...
1 vote
1 answer
80 views

What is an apporpriate design pattern when dealing with Pandas and databases?

We're dealing with a lot of "data analysis", basically different sorts of data mangling, aggregations and calculations using Pandas. Usually, the data is time series data. All underlying ...
1 vote
0 answers
89 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:...
  • 215
2 votes
2 answers
89 views

Sharing a data class in a flow

Suppose there is a flow of functions in C++ step1(); step2(); step3(); step4(); step5(); and they interact by adding and modifying data on a data class D (only data, no functions). For example, step1(...
  • 131
0 votes
0 answers
49 views

How to improve the Mediator algorithm when new widgets are added?

i want improve mediator algorithm when the new widgets are added.How do I make changes in this form? plas help me and the code:
1 vote
3 answers
204 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; } ...
16 votes
6 answers
6k views

Accessing enemies' locations quickly in a 2D game

I have a simple 2D game which has squares, player (teal) and enemies (red). class Game { List<List<Square>> map; Player player; List<Enemy> enemies; ... My problem is that I ...
  • 320
2 votes
1 answer
290 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 ...
1 vote
1 answer
146 views

Is this a good use of events?

At my company we are revising some backend architecture. I think I have identified a use case where event streaming (for example with Apache Kafka or RabbitMQ) makes sense. Because me (and everyone ...
  • 45
4 votes
1 answer
101 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 ...
  • 149
2 votes
2 answers
318 views

Is it good design to have a repository update multiple entities?

I'm building a web application using Laravel. I use the repository pattern as my data layer. Imagine there's some entity like Product and a product can be assigned to a ProductCategory. The Product ...
2 votes
2 answers
122 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 ...
  • 27
4 votes
4 answers
593 views

Giving multiple components access to a single database

This is in context of a distributed computing. There is a Service A which owns a database and hosts APIs for updating an entities in this database. As time went by, the service has evolved and we are ...
-1 votes
1 answer
61 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 ...
  • 127
2 votes
0 answers
45 views

How to have only one consumer handle a long running task at a given point?

I need to design an application which makes requests to an external API. External API has a hierarchy of entities: User which contains ListOfItemss which contain Items. I need to get data on all Items ...
  • 165
0 votes
1 answer
136 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 ...
  • 103
2 votes
3 answers
267 views

What is the name, or design pattern, for something that calls a list of functions one by one?

The following design emerged from using Azure Durable Functions with lots of fan out, which turned out to not work very well. Our starting point was an Orchestrator with a companion Durable Entity for ...
1 vote
1 answer
148 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 ...
1 vote
1 answer
116 views

Pattern to convert different types of similar unchangeable objects to the same object

I have an existing system that inserts books into a library database, and I want to generalize it to include other media. The other media is similar, but not exactly the same, and all media are third ...
  • 23
1 vote
1 answer
137 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 ...
  • 23

1
2 3 4 5
87