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
-1 votes
1 answer
126 views

How to extend many types of classes, keeping some of their methods?

I have a base abstract class that have many methods, and multiple subclasses that extends it and implementing the methods. I have another type of subclass that need to wrap the subclass and extend ...
user1941348's user avatar
1 vote
1 answer
71 views

Querying objects in a list by class type vs string identifier - Best practices

I have a class Character who has a list of Spell objects that he can cast. abstract class Spell { name: string manaCost: number abstract cast() { ... } } class InvisibilitySpell extends ...
Michael Moreno's user avatar
2 votes
2 answers
772 views

How to design inter-service communication with notifications microservice?

I'm creating an application based on the microservice architecture and stuck on notifications microservice design. Basically it should be a service that notifies users about events happening in the ...
Ledorub's user avatar
  • 121
0 votes
3 answers
330 views

What is the difference between these two MVC diagrams?

I want to understand what is the main difference in these two diagrams when it comes to the Model-View-Controller pattern. If there is a difference, how should I choose to construct my program? What ...
codertryer's user avatar
-1 votes
2 answers
74 views

Java: Autogenerating documentation for Strategy Pattern with lambdas

Situation Object MyObject needs to be sent to one of our downstream systems depending on the enum value of its field myField. public class MyObject { private MyEnum myField; public MyEnum ...
downwash's user avatar
1 vote
2 answers
206 views

It is okay to create an interface of interfaces?

Let me first describe the situation I have a component that uses dependency injection through a service locator. In the first scenario (image 1) the component needs a class that implements Interface0, ...
DanielJaramillo's user avatar
-1 votes
1 answer
424 views

How should the structure of external API calls in an electron application be designed?

In this scenario, my renderer process' goal would be to make an HTTP request to an external web server and receive responses. My question is: which options below would be more secure, give a future ...
yokus's user avatar
  • 7
-1 votes
1 answer
238 views

Avoid use of the visitor pattern in this very common scenario

Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it. We already know that we ...
blow's user avatar
  • 109
1 vote
2 answers
183 views

Wrapping Business Logic In Extension Methods For POCOs

I have recently stumbled upon a use case of extension methods and wanted to gather some design thoughts. The problem: A IEnumerable of a POCO and within that list there should exist a POCO that ...
Stevenfowler16's user avatar
0 votes
1 answer
229 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 ...
Samuel Muldoon's user avatar
0 votes
0 answers
76 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 ...
Baffo rasta's user avatar
1 vote
0 answers
93 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 ...
sfiss's user avatar
  • 818
3 votes
1 answer
155 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, ...
Amal K's user avatar
  • 101
3 votes
2 answers
305 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 ...
Matthew Layton's user avatar
-1 votes
1 answer
94 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 ...
Meck3l's user avatar
  • 17
-1 votes
1 answer
95 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 = ...
Samuel Muldoon's user avatar
2 votes
2 answers
182 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 ...
Markus Meskanen's user avatar
2 votes
3 answers
245 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 ...
Nmaster88's user avatar
  • 167
1 vote
1 answer
617 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....
Michael Moreno's user avatar
1 vote
3 answers
321 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 ...
manimerz's user avatar
1 vote
1 answer
152 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 ...
micheal65536's user avatar
1 vote
1 answer
862 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 ...
Agah Shamekhi's user avatar
0 votes
1 answer
94 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 ...
nrob's user avatar
  • 111
0 votes
1 answer
186 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 (...
kaan_a's user avatar
  • 155
1 vote
4 answers
265 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 ...
DK13's user avatar
  • 29
1 vote
1 answer
153 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; ...
Accollativo's user avatar
1 vote
2 answers
137 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"...
Subliminal Hash's user avatar
2 votes
2 answers
362 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 ...
crommy's user avatar
  • 129
0 votes
1 answer
123 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 ...
ScottishTapWater's user avatar
-1 votes
1 answer
193 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 ...
JS Lavertu's user avatar
2 votes
1 answer
142 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 ...
john doe's user avatar
  • 141
-1 votes
1 answer
86 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 ...
subtlecode's user avatar
-2 votes
1 answer
97 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. ...
David's user avatar
  • 1
3 votes
3 answers
385 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 ...
Mike Nakis's user avatar
  • 32.2k
0 votes
1 answer
220 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 ...
RedYoel's user avatar
  • 123
0 votes
2 answers
365 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 ...
Shadow43375's user avatar
1 vote
1 answer
215 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 ...
highviolet's user avatar
0 votes
0 answers
114 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:...
a.t.'s user avatar
  • 225
1 vote
2 answers
97 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(...
tqw's user avatar
  • 121
0 votes
3 answers
651 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; } ...
Lionel du Peloux's user avatar
15 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 ...
MaLa's user avatar
  • 310
1 vote
1 answer
2k 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 ...
Gabriel Morishita's user avatar
0 votes
1 answer
160 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 ...
Puck's user avatar
  • 45
3 votes
1 answer
120 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 ...
Lucas's user avatar
  • 139
3 votes
2 answers
1k 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 ...
user2190492's user avatar
1 vote
2 answers
154 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 ...
Meck3l's user avatar
  • 17
3 votes
4 answers
760 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 ...
Sanath Kumar's user avatar
-2 votes
1 answer
70 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 ...
Snorlax's user avatar
  • 117
1 vote
0 answers
71 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 ...
Yos's user avatar
  • 157
0 votes
1 answer
157 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 ...
mxmissile's user avatar
  • 103

1 2
3
4 5
89