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

In poltergeist, whats wrong with "solely to trigger or initialize several other objects"? Isn't it is a good use of encapsulation and reuse?

After reading What differentiates function objects from poltergeists?, according to the definition of poltergeist, I still don't understand why would "poltergeist" be a bad pattern: A ...
wcminipgasker2023's user avatar
0 votes
1 answer
275 views

How could I apply the strategy pattern to a react component? [closed]

For the following component, how would I extract the unit logic to allow for composition? In my actual app I am trying to reduce the amount of logic encoded in the component and I have decided that ...
Tyler Kasper's user avatar
2 votes
9 answers
3k views

Is it an anti-pattern to use interface for entity?

I read an article about that using an interface for an entity is an anti-pattern for these reasons: Your interface signature is identical to your class. There’s only one implementation of your ...
Mercury's user avatar
  • 53
0 votes
1 answer
121 views

What C# Object Composition strategy would you apply for CoreObjects with a governing 'ObjectType' property

In a C# ASP.Net Core Web Application I have a Domain Model CentralDesignObject made up of many component objects & properties, producing a significant amount of derived/calculated values. This ...
freedomdev's user avatar
1 vote
6 answers
368 views

How encapsulating what varies can help us?

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
Mehdi's user avatar
  • 29
0 votes
2 answers
155 views

Is this a bad pattern for reporting/audit?

We have a large code base with lots of workflow data (camunda) that does this: Create a reporting event in the codebase Give it a code + payload Put the item on a message queue Consume queue ...
mabeloo52's user avatar
0 votes
0 answers
57 views

Java - How to build a library to record runtime data?

I'm working on building a library in Java which could provide the ability to record runtime data. For instance consider the below code: public interface ItemElement { public int accept(...
user762421's user avatar
0 votes
3 answers
165 views

Event-driven design with delayed consequences

EDIT: more direct situation I need to design a program that will create particular objects and run computationally intensive procedures using its fields in order to update other fields. When a ...
Raphaël's user avatar
  • 119
1 vote
1 answer
160 views

Implementing MVC in C++ with minimal boilerplate despite lack of reflection

Powerful reflection capabilities make implementing nice architectural design patterns such as MVC and Dependency Injection very simple in languages like Java and Kotlin. In particular, reflective tags ...
The_Sympathizer's user avatar
0 votes
2 answers
122 views

Best way of creating different instance types(facotry method) with business logic?

Say I am trying instantiate an instance of a Table. Table here denotes a restaurant table used for eating. Say I have 3 different table types enum TableTypes { SMALL, MED, LARGE } I have ...
curiousengineer's user avatar
0 votes
1 answer
118 views

What is the name of the approach (practice) when several unrelated entities are returned at once in the response to a request [closed]

For example, for a mobile frontend, you need to get all the data for rendering at once. The interface is divided into blocks, in which there can be both blocks with a catalog (categories) and other ...
fogel's user avatar
  • 21
3 votes
0 answers
556 views

Is MVVM appropriate for a .NET MAUI Blazor hybrid app?

I am preparing to create my first .NET MAUI Blazor hybrid app. It is a relatively new technology so there aren't a ton of resources to look at, but of the ones I have found, they are all structured ...
Sudsy1002's user avatar
  • 139
2 votes
1 answer
318 views

Domain models: Can they be an abstract class

When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the ...
Vitor Figueredo Marques's user avatar
6 votes
7 answers
7k views

How to avoid repeating "a==b" when comparing "condition a" and then "condition b" and then...?

For example, I have an object: public class Obj{ public int a; public float b; public String c; } I need to find best "Obj": largest a and then largest b and then longest c: int ...
wcminipgasker2023's user avatar
0 votes
1 answer
122 views

Design of system pushing data to multiple systems

I have a ASP.NET Core backend (with Azure Service Bus) and a Blazor Server frontend. The purpose of the backend and the frontend is to trigger manual and automatic pushing of single data points (...
wetfield's user avatar
0 votes
1 answer
740 views

Some approach or Design Pattern to implement same method different parameters of Interface class

I am using the Flyweight pattern to cache and reuse objects of the different classes. For example, I have a Shape interface class and multiple types of Shapes implementing the methods from the ...
Himanshuman's user avatar
0 votes
3 answers
464 views

Use of Visitor pattern rather than enums

Lets say that a enum exists: public enum SomeEnum { FirstValue, SecondValue } It's use is spread through the code and all sort of wonderful logic hangs off it. If we now add another entry (...
Postie's user avatar
  • 11
1 vote
2 answers
459 views

design pattern to avoid deadlock with mutex in golang

What would the appropriate design pattern to avoid deadlock when several functions use the same mutex ? It is quite easy to forget what method uses the lock and so it happens that you call a function ...
cylon86's user avatar
  • 111
2 votes
1 answer
105 views

Converting the classes with multiple dimension to Bridge design pattern

Bridge design pattern is something which is very confusing and GOF does not do justice with beginners in the definition. I was asked in my current organisation to add one more dimension to our class ...
Himanshuman's user avatar
4 votes
1 answer
294 views

Dealing with global variables required by badly-written library

I am working with a library that is somewhat poorly written. In order to function, it requires several global variables to be declared and sometimes even maintained by my own code. I really don't ...
Infinite_Maelstrom's user avatar
0 votes
0 answers
31 views

Choosing a Pattern for Handling Different View Models in a Service Method

I'm working on a fairly large but standard dotnet core API. Here's a simplified sample: // Simplified example of a controller public class VehiclesController : ControllerBase { private readonly ...
Carel's user avatar
  • 113
-2 votes
3 answers
126 views

What are the pros and cons of different combinations of objects and arrays for data storing?

From the article JavaScript 2D Array – Two Dimensional Arrays in JS, I see one way to store data is to put all properties of each element into one array: let dataRepresentation1 = [ ['John Doe', ...
Ooker's user avatar
  • 315
0 votes
0 answers
110 views

Is having many thin factories an antipattern?

I need to perform the following task: for a user [email protected], store a blob of data into their dedicated data store. DataStoreService is what actually stores the blob of data in the user's store, ...
async's user avatar
  • 854
0 votes
3 answers
322 views

Why is Dependency Injection called "alternative of global state"?I think global state still exists

According to Why is Global State so Evil?, I believe we should avoid global state, so suppose I have an App that count user clicks in all pages like it: public class GlobalState{ public int ...
wcminipgasker2023's user avatar
4 votes
4 answers
554 views

When should tuples be used as an argument instead of an array?

I hope this isn't too off-topic/opinion-based, I'm new here. I want to pass three elements of the same type into a function. The three elements are unique cards of a deck of cards, so they're not ...
David's user avatar
  • 59
1 vote
2 answers
182 views

Is there a name for this pattern of sealing base classes to a strict set?

In C#, it's possible to create a strictly sealed set of classes that inherit from a base that cannot be further extended like so: public abstract record MyBase { public sealed record A: MyBase; ...
ScottishTapWater's user avatar
1 vote
0 answers
85 views

Mimic public/private data members in C with hidden static arrays

Context I'm designing the software architecture of a safety critical software written in C, under DO-178C (DAL A) and with a Code Standard based on MISRA-C 2012, but no fully compliant. It is the ...
Sam's user avatar
  • 31
5 votes
1 answer
183 views

Is tag dispatch as used in CppCoreGuidelines T.65 antiquated?

The CppCoreGuidelines contain the following: T.65: Use tag dispatch to provide alternative implementations of a function [...] Example struct pod_tag {}; struct non_pod_tag {}; template<class T&...
Jan Schultke's user avatar
3 votes
0 answers
210 views

API Gateway Design Pattern - Backends for Frontends

I am contemplating the use of the design pattern API Gateway, specifically the Backends for Frontends derivative. We have a number of 3rd party software packages that expose an API. Over the course of ...
Ryan Wilson's user avatar
0 votes
1 answer
731 views

How do Repository and Data Mapper patterns work together?

I've seen a variety of discussions talking primarily about the question of the difference or not between the Repository and Data Mapper persistence system design patterns; but I think I have a decent ...
The_Sympathizer's user avatar
1 vote
1 answer
88 views

In the state pattern, what happens when the action doesn't depend only on the state?

I have some doubts about the state pattern, but I think it is better to ask one question at a time, so it is easier to focus on the answer. The state pattern establishes which actions can be performed ...
Álvaro García's user avatar
0 votes
2 answers
735 views

Mediator Pattern in c# - using a mediator to trigger policies

I'm wondering how i can implement what Im calling "business policies" in my code? For discussion purposes, let's say I have two separate contexts - synchronizeUsers and Licensing. The ...
dot's user avatar
  • 561
1 vote
4 answers
377 views

Is there any intent behind SRP other than SoC

Edit based on responses so far I am starting with an edit so as to save future contributors from going down the same path others have. I am only interested in contributions that stick to the exact ...
Ash's user avatar
  • 219
2 votes
2 answers
303 views

Data getter inside Model or ViewModel in MVVM

I'm working on an app I created for myself using the MVVM architecture. On my ViewModel I have a list_items that, when changed, updates the corresponding UI element on the View. The list of items ...
João Pedro's user avatar
3 votes
2 answers
658 views

Standard error codes vs custom error codes in C

I am working on improving the code quality and portability of my C library, specifically a ring buffer implementation, that will be used in larger applications. I have encountered a dilemma regarding ...
Usman Mehmood's user avatar
0 votes
0 answers
125 views

How to handle dependency injection in a library to avoid frequent breaking changes?

Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
srk's user avatar
  • 127
-1 votes
2 answers
112 views

Flexible design approach vs maintainabilty/verifiability

Currently, I have to define a general design approach concerning the future extensibility of a software written in C#. The software is built in modular design: A main part doing the general handling, ...
Thern's user avatar
  • 105
-3 votes
6 answers
593 views

What's the purpose of having a DTO going into a service? [closed]

Let's say this application has a User and each user must have a firstName and a lastName. We could simply call the service with two strings from the controller (method A): class UserController { ...
user430236's user avatar
0 votes
2 answers
131 views

Services: Which structure is a better idea?

I'm designing my service layer for a GraphQL API and there are many situations in which I can't decide if code relating to a table should belong in it's own class, or the class that 'owns' the data. ...
J Doe's user avatar
  • 101
1 vote
1 answer
135 views

Silently re-using data vs requiring the user to pass a "re-use" argument?

Context After creating a (bash) CLI interface that creates self-signed SSL certificates (for onion domains), the user can choose to re-use some of the data that is created in past runs. For example, a ...
a.t.'s user avatar
  • 225
0 votes
1 answer
105 views

Multi dimensional lookups

I am looking to see if there is a general design pattern or strategy to handle a use case I see often in our codebases. My best attempt to generalize this use case is "Map permutations of n ...
jason.zissman's user avatar
0 votes
0 answers
141 views

How to maintain state for a turn-based game in django

I am using django to develop a turn based chess variant. I just finished using django-channels to create a lobby and match 2 players together. Now, I need to make them play each other and I'm thinking ...
Alex Li's user avatar
  • 109
0 votes
2 answers
193 views

Usage of overrides in the State design pattern

Imagine a situation where out of 5 state implementation classes the implementation of a method only differs on 2 of them (i.e. 3/5 share the same implementation for a particular method). This ...
PeterTheLobster's user avatar
0 votes
1 answer
312 views

Observer pattern using static events

I'm working on a game prototype: I have a Cell class which, given a mouse click on its collider, can raise an event that should be listened in two different modules: Camera and UI. The Observer ...
vandermies's user avatar
0 votes
2 answers
250 views

What is the difference between C++ Composite and Chain of Responsibility patterns?

A Composite delegates calculations of unknown depth to a virtual method. A Chain of Responsibility passes events to an arbitrary deep line of handlers. Sounds the same to me. What am I missing?
Vorac's user avatar
  • 7,119
0 votes
2 answers
255 views

How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?

I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1()...
goober's user avatar
  • 17
0 votes
4 answers
281 views

Object matching using generic method? [closed]

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 ...
Siddharth Trikha's user avatar
-1 votes
1 answer
76 views

Optimal OOP security for PubSub - Should mutual consent be required?

I am implementing the Publish-Subscribe pattern. I have class Broker and interfaces IPublisher, ISubscriber. interface IPublisher { broker: Broker; publish(channel: Channel, data: object): ...
Michael Moreno's user avatar
2 votes
1 answer
201 views

Socket Class Design C++

I am currently trying to design some C++ classes that encapsulate POSIX sockets and their relevant functions. I want to try and design classes that are simple, elegant, and make the best use of design ...
nick2225's user avatar
  • 147
3 votes
1 answer
197 views

GOF class diagram for Builder pattern appears to contradict its corresponding sequence diagram

In the Design Patterns: Elements of Reusable Object Oriented Software, the Gang of Four present the following canonical form for the Builder pattern: In Appendix B the following is mentioned ...
user32882's user avatar
  • 267

1
2
3 4 5
89