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

What's the difference between Strategy Pattern and IoC

In both the Strategy Pattern and in Inversion of Control you can exchange parts of an object that allows scalability and easy-to-exchange parts. I am referring to this and this Both use an interface ...
2
votes
2answers
62 views

How to model files which contain values that depend on and change with other values?

I want to parse a binary file and track the values and positions of certain properties within it. Reading them is not that much of a problem, since I know the rules they follow in terms of where they ...
-5
votes
1answer
67 views

How to organize the following code in a better way? [closed]

I've a class which performs an operation (say A). I've few logic which has to happen before A happens and few during A happens and few after A has happened. interface ILaunchInterface { public ...
2
votes
3answers
227 views

What is the name of this concept/design pattern for blocking another component from running?

Description of Desired Behaviour I have the following scenario: Component A can run freely as long as it is not blocked. Any other component can block the component A from running at any time. ...
2
votes
1answer
58 views

What is a good API design for different available actions per mutually-exclusive states?

I am implementing a entity that has multiple mutually-exclusive states. In each state, there are different set of actions (let's say, transitions) that may take the entity to a different state. ...
-2
votes
1answer
64 views

Is this an example of a wrapper function?

I'm working on an application in python. One of the functions we have is called def createThread(user, status, title, ...): # some code here system.db.runUpdateQuery("INSERT INTO table(value,...
3
votes
1answer
351 views

What is a “tear-off” in software design or patterns?

What is a tear-off? I ran across the term reading Flutter documentation: Returns a CallbackHandle that can be provided to PluginUtilities.getCallbackFromHandle to retrieve a tear-off of the ...
0
votes
3answers
204 views

what is the best way to make one file appear in two directories

I'm trying to develop a CSS library where I style each element on an example HTML page. However, I came across those two elements (<cite> <blockquote>) whose examples must be shared with ...
-1
votes
2answers
96 views

where to put Read/Write threads in c++ classes

I am programming a UART interface (in LINUX) and I want to use a class for that. The way I have it right now is I have a method for write and one for read. The reading is started in a new thread to ...
0
votes
1answer
65 views

Is using an enum to differentiate different events in an observer pattern plausible if it's on a small scale?

I need to collect statistics during an algorithm. To not mix the statistical code with the algorithm code too much, I'd like to decouple that by publishing "statistical events" that can then be ...
0
votes
1answer
117 views

Is there ever a reason to NOT call Environment.ExpandEnvironmentVariables(path) on string file paths?

It was recently requested that I accepted system Environment Variables in paths for my applications and that was really the first time that's come up for me and I didn't even realize that C# didn't ...
0
votes
3answers
199 views

Builder Pattern - Must it be part of The same Class?

For complex object creation, I am quite fond of Builder Pattern. My 1st question is "Do I need the Builder to be inside my complex class blueprint, or Could I actually have it outside?" e.g. Are the ...
1
vote
1answer
75 views

C# class design for clear API wrapper

We are creating an office application in C#. Originally, the persistent data like customer details, orders, agenda, statistics, etc. were stored in a local SqlServer database on a server. The ...
2
votes
1answer
35 views

Event Handling in Pygame

I am working on setting up a game in pygame and I've noticed that there isn't really a lot available for event handling. Basically, pygame has a queue of events that you can pull and iterate through ...
0
votes
1answer
81 views

OO Design Principles for document parsing

The have been tasked to create a software application that will parse a set of 150 documents, extracting certain data elements (not html elements), such as tables, comments, invalid content, invalid ...
16
votes
3answers
5k views

Is using Observer pattern a good idea while building a Chess Game?

I am trying to design a Chess Game using OOPs concepts that has a UI element to it. My idea is to show the number of squares / cells a piece can travel to when selected. Basically I want to show the ...
0
votes
1answer
46 views

Is event-sourcing and event-driven design works in scalable architecture for a wallet?

considering you need to design a simple wallet service that keep tracks of transactions, and give balance for each account. I started designing the solution using event-driven architecture, so every ...
2
votes
2answers
177 views

Using state pattern to remove if else statements

I need to get rid of if, else statements from my code as it is a smell. I know you can implement the state pattern to get rid of them, however in my code I'm checking if the string input is a certain ...
0
votes
1answer
42 views

Is it permissible to have relationships to parents of parents for JSON:API resources?

I have the following hierarchy: venue -> concert -> booking And within booking I have a relationship for the concert. But should the booking also have a relationship to the venue? Or is it bad ...
1
vote
1answer
134 views

How to develop independent logical blocks without having too many microservices?

I have a service which is composed of various independent small "blocks" of logical code. A block stands for a class which implements an interface "IBlock" which includes an "Execute" function that ...
0
votes
1answer
274 views

Does Asp.Net Identity worth the overhead?

I'm creating web applications using Asp.Net Core Identity with N-Tier architecture. Lately I've been discovering many properties of this library that I didn't know before as I need to configure the ...
0
votes
0answers
32 views

Is it okay to include assets (css, js) outside of webpack?

i'm making an app in Rails 6, and i've included my css/js assets in public direction. Is it fine? I know that webpack makes code faster and lighter. But do i make some mistake if i just include code ...
0
votes
2answers
88 views

Design pattern or structure for when the value of different variables are related

Is there a design pattern or structure that helps to organize code with variables whose values are related? For example, let's imagine I have an object with three properties (gonna use some pseudo ...
-1
votes
1answer
42 views

Confused about data access layers and modelling or filtering layers

I've created a database and included in the tables are these three relatives Game GameHasPlayer Player I've created a data access API project, with simple methods for getting filtered results: ...
3
votes
3answers
285 views

Should a standard factory always generate a new instance?

According to my understanding on factory-method, factory should always return a new instance, meaning no cache, So in essence, every time when the factory method is called, there should always be a ...
8
votes
3answers
716 views

“Depend on abstractions, not on concretions” what is the exact meaning of this term

I was reading SOLID principles on a website, in which for D - Dependency Inversion Principle it says: “Depend on abstractions, not on concretions” In other words. we should design our software ...
2
votes
1answer
58 views

How to handle the Dependencies between Secondary Actor Adapters in the Hexagonal Architecture

I am applying the principles of Hexagonal Architecture (Ports and Adapters) and one aspect is slightly bothering me. In my opinion, the ports and adapters of the secondary actors should completely be ...
1
vote
1answer
448 views

How to avoid circular references with EF Core and Global Query Filters?

We're working on building a multitenant application, and we're using Entity Framework Core as our base data provider. With EF Core, you can use Global Query Filters to define custom filters that apply ...
1
vote
0answers
74 views

Appropriate way to organize dependency with external class avoiding high coupling

I was design a server communication module of native application. As starting point for now I have 3 classes: HttpSession — class which contain all necessary data for sending requests. ...
-3
votes
1answer
117 views

What kind of factory method abstract singleton design pattern is this?

I made a code that seems to mix Singleton design pattern, and Fatory method. But my factory method is in an abstract class inherited by my Singleton ... what the hell have I created ? Does it have a ...
4
votes
1answer
69 views

Shared access tokens in a distributed system

I'm building a system that horizontally scales with many nodes. Any of these nodes could consume an API that's hosted on https://example.com/api. The authentication for this API is token based. My ...
2
votes
1answer
126 views

Better way to implement a feature with turn on/off based on a flag

I'm trying to implement a feature with option to turn it on/off based on a flag. I'm doing it in the following way which I feel like a overkill, public interface Feature { public interface ...
2
votes
1answer
46 views

Web application demo mode or Introduction mode

I have a web-app with multiple functionalities and each functionality has multiple workflow/process. For example, Workflow A has Steps A => Step F, Workflow B has Steps A1 => Steps G1 and many more ...
6
votes
5answers
699 views

Implementing a hash table with true concurrency

This was recently a question I was asked in a screening and it got me thinking. I never totally settled on how the conversation ended, and I did some digging. None of the answers I saw seemed ...
1
vote
1answer
42 views

design points calculation based on rules defined in table

Have a database table which business / sales folks could and will keep modifying: year from | year to | points ----------------------------- 1930 | 1943 | 20 ----------------------------- ...
1
vote
1answer
139 views

What should I name this area of my architecture?

I am developing an architecture for a new MVC system. The legacy system has a layer it calls "facade", but it is not the classic GoF Facade. It is more like a service aggregator. It is used as a ...
3
votes
1answer
136 views

Design Pattern: Extending existing functionaliy of ENUM

Let me explain the problem I am dealing with. I have a custom (jar) API that I use in my production code. This API contains an ENUM that looks as follows: public enum Cars { AUDI("BERLIN", "...
0
votes
1answer
53 views

Prioritizing messages sent over a socket

I'm looking at the source code for a client - server program that communicates using TCP sockets. 5 connections are used to communicate, named very_slow, slow, medium, fast and very_fast. A socket is ...
2
votes
2answers
119 views

Should microservices in an event sourced architecture not communicate directly with one another via REST/gRPC/etc?

I'm trying to wrap my head around event sourced architectures. It seems like common advice is to have small events with as little info in them as possible (opposed to large events with everything in ...
0
votes
0answers
107 views

Granular application security in a multitenant application that utilizes a centralized identity server

We are currently rewriting many of our internal desktop applications and converting them over to white-labeled, multi-tenant web applications. As part of the transition, we've setup a centralized ...
0
votes
3answers
57 views

Get the right class in base of an argument - Pattern

I have a little doubt on about get a class in base of an object passed to a function. In my case, I can two different types of object: classA, classB that have the same interface. I have to pass one ...
1
vote
1answer
47 views

c# xml import and validation with different document versions without XSD

Context: I have a case where I need to extend some existing functionality for loading a new version of an xml file into a system (new fields, some mandatory that were not mandatory before, etc). The ...
2
votes
4answers
213 views

Is it a bad practice to query remote resources inside validation?

Watching this talk about Symfony Forms and validation, at 23:06, I got stuck with a doubt I couldn't find a satisfying answer to: Is it a bad practice to execute a query (or a web request, or a side ...
5
votes
5answers
325 views

How to avoid many objects in constructors when many steps are performed by a class

I have a process which must do 8 steps, in a particular order. One of the step involves sending an email, another one going on a distant FTP server, another one querying a database, and so on. Now to ...
1
vote
2answers
123 views

How to implement a cursor iterator?

In the "Structure" section of the Iterator design pattern, the book Design Patterns: Elements of Reusable Object-Oriented Software defines the Iterator class with four basic operations: First, Next, ...
0
votes
1answer
60 views

How To Design Event Handlers With Different Parameters

I have an interface Event and a class Agent. I want to be able to write something like agent.handle(event). However, the classes that implement the event interface will all have different fields ...
6
votes
2answers
270 views

Is the builder pattern appropriate to use to update Objects in a Service layer?

Currently, in our service layer, we pass an id as well as a new updated value, something akin to updatePersonName(Person person, Name name) which, in turn, calls the corresponding repository ...
2
votes
1answer
246 views

How the MVC increase code testability?

I am learning MVC design pattern as an android developer and I've been seeing that it facilitates the testability of code. I understood this concept, but in real case I'm frustrated. Can someone ...
2
votes
2answers
93 views

Processing user commands and parameters

I'm writing a GUI application which needs the facility for users to interact with the system and execute tasks via a sort of command line interface. The user will type commands in a text box, with ...
4
votes
6answers
2k views

Making recursion optional: Bad practice?

Let's say I have a function like this: /* Mode is a bool that determines whether the function uses it's recursive mode or not */ public static int func(int n, boolean mode) { if (!mode) ...

1 2
3
4 5
76