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
0answers
20 views

C# Web API Requests and multipart forms with json and files and not buffering the filestream in memory

I'm looking for some C# web API architecture advise on how best to minimize my memory when doing a "multipart/form-data" request which consists of a json payload with a single file upload. ...
0
votes
0answers
37 views

State Pattern: Changing object behavior based on more than one field and consistency between their values and state value

I'm Trying to learn about State Pattern. In most of State Pattern examples that I have seen, methods of class change their behavior based on just one field (I mean before applying State Pattern and I'...
1
vote
1answer
69 views

Prevent users with multiple sessions using a single use voucher

I'm working on a .Net eCommerce site that allows users to use vouchers to get free products, discounts etc. The problem I have is that there have been instances of users, who have been issued single ...
0
votes
2answers
169 views

Can a class be considered as a factory even though it only creates one concrete type of objects?

I have a simple class called Link that contains some properties, and use different classes for creating different types of links. My code looks like this: class Link { String reference, label, ...
0
votes
3answers
97 views

What should be the optimal management of end user messages in N-tier architecture?

I'm curious about your thoughts on this subject that we have discussed with the people around me. Especially at the architectural stage, in which layer is the most optimal and efficient way to use the ...
41
votes
13answers
6k views

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Consider your have an enumeration that looks like this: enum ProcessingType { CONFABULATION, RETICULATION, SPLICING; } And you have a web-service that looks like this: class WebService { ...
0
votes
0answers
33 views

Query for each doucment or include IDs in document itself and query for all documents with ID?

I am working on a project where there will be different kinds of accounts that use Auth0 for auth and authz. I want to have it so that an account will query my backend to get back documents that ...
3
votes
2answers
230 views

How to structure many complex conditionals on a class

I have a class (as a protobuf) OrderChange, that represents when an order (imagine Amazon.com) changes: message OrderChange { Order old_order = 1; Order new_order = 2; } message Order { ...
0
votes
2answers
118 views

Design for three classes with partially shared logic

I am looking for a suitable design which uses composition to allow three classes to share some logic. The problem I am solving is that I have to read 3 different json configuration files from my ...
-1
votes
1answer
77 views

Subclasses with same behaviour but different attributes for different inputs

Say I have two object types of the same interface MyObj (I am using python in this project so I will use the same for the explanation) class Foo(MyObj): a = [5, 10] class Bar(MyObj): a = [[1, ...
2
votes
2answers
306 views

Is returning true or throwing an exception good or bad code practice?

I am focosing on learning better design and wondered if this code is good or an antipattern? The function validate return true if data is correct, else it will throw an exception with a message to ...
2
votes
2answers
75 views

Modeling combination of two independent abstractions

I am building an app (.NET, but whatever) which is supposed to be able to send notifications to users. Each Notification can either be a Reminder or a Newsletter, and I'll possibly add more types in ...
-1
votes
1answer
149 views

Source of "... against the interface, not the implementation"

For a paper I am writing, I need to find the origin of the following two phrases: Code against the interface, not the implementation and Test the interface, not the implementation (Note: the ...
1
vote
2answers
42 views

Getters and (static) processor vs multiple processor wrappers

I've got a class which stores two data series like so. I need to do some complicated processing on each of these arrays, but for now we'll just get the average of each data series. I could either do ...
1
vote
4answers
329 views

How to convince colleagues to stop writing static classes [closed]

I recently joined a new company. After working on some projects I noticed a pattern. Every project contains a lot of static classes. A lot of static Helper classes. ApiHelper JsonHelper UmbracoHelper ...
0
votes
1answer
75 views

Inject configuration files into the injector is it an antipattern?

I'm trying to design a system that inject configuration of each component into each class. project structure: |features --|component-a component-a.service.js component-a.config....
-3
votes
1answer
101 views

How to implement state machine to card games such as poker or russian poker?

These are my class designs: I also have Controllers where I can create table, create users add users to table, deal hands simulate user bets using PostMan (Above classes are game engine classes, I ...
1
vote
3answers
227 views

How to use abstract factory on interacting widgets

Context In many GUI frameworks, it is very common that widgets are placed in a container to arrange them visually in a window. For example, in Gtkmm, a window with a label and a button (side by side) ...
0
votes
1answer
45 views

How to design an application for stalling file processing?

I have an application that is receiving a live stream of files, I am using active MQ for listening to the file arrival in s3. As soon as the file arrives in s3 my application downloads the file and ...
-1
votes
3answers
179 views

Running series of steps depending on implementation

What is the "best way" to implement something like this: I have a list of steps that will be iterated and ran for an IContext instance. But, some steps will only apply to a specific instance ...
0
votes
1answer
137 views

Does the builder/factories pattern apply to this problem?

I have the following code and I am not sure if the builder factory is the best approach to solve this code duplication. createA(a, b, c, e: {e1, e2}){ return{ a b c e } } ...
0
votes
1answer
52 views

Design class with different dependency requirements based on configuration

I’m struggling a bit to design the following class: It’s a service class with multiple methods. It depends on a http client interface which must be created in the factory method and can’t be passed ...
0
votes
1answer
97 views

How to combine data from multiple sources into the same object?

I've been running into a common pattern when requesting data from multiple sources: Have a list of objects from one source (e.g. a list of Cars) with an id property and a few other properties ...
0
votes
2answers
283 views

Is "error first" better than "if-else", why? [duplicate]

I have an eternal discussion in my work about why "error first" is "worng". In order to ensure what I try to tell with error first is the following code pattern: if condition: ...
0
votes
6answers
221 views

If it is a bad practice to use an interface if only one class will implement it, what is the purpose of IoC container?

Okay, first of all I understand the concept of IoC container! It's used to implement automatic dependency injection so you won't have to manually inject dependencies to class. It can automatically ...
0
votes
2answers
121 views

How to enforce matching, but unknown interfaces

I am challenging my OO design skills and started an ambitious project that is supposed to be highly reusable and extensible. It is supposed to be kind of a framework for evolutionary algorithms. Maybe ...
-1
votes
2answers
135 views

Implementation of method differs only in one line

I have 2 implementation of the interface: public interface MyInterface{ void getCollectedData(MyData mydata); } public class MyImpl implements MyInterface{ public void getCollectedData(MyData ...
1
vote
1answer
141 views

C# how to implement a factory class which doesn't require an argument passed to indicate objects type?

I currently working on a parser project in C# and have run into problem. I have an entity folder within my project and within it I have: Entity IEntity.cs (defines a contract for entity classes) ...
0
votes
0answers
33 views

Which patterns use to design a turn based board game? [duplicate]

I am struggling to design a board game architecture since I am trying to keep it as generic as possible in order to improve its flexibility to extensions in case of new features, but doing that I'm ...
2
votes
1answer
156 views

How to correctly use the Factory Method pattern?

I'm currently re-designing my hobby project and I'm trying to apply what I've learned recently from design patterns. Summary for context: the project listens for TCP commands from my phone (using ...
-1
votes
1answer
81 views

Adapter pattern for formatting third party API responses

I've been refactoring some of my procedural code to OOP, and I'm wondering if using the adapter pattern is overkill in this case. Basically, I created a Order class. All class properties are a field ...
3
votes
2answers
252 views

How to use visitor pattern when objects change frequently

It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently. What if the objects are changing too though? For example we ...
-2
votes
1answer
103 views

Design Patterns in C++: What is the best way to implement an interface with a generic type? [closed]

I would like to use a generic interface that has been implemented. I have two classes as such: class App { MainWindow<State> mainWindow; protected: virtual MainWindow<State> ...
1
vote
0answers
50 views

Design pattern for configurable factory sought

Apologies for the title, I'm sure there is some well-known phrase for it but I don't know it. I have a solution for a problem, but I'm not satisfied with and am seeking inputs to help me improve it. ...
0
votes
0answers
48 views

What is the best way to share data between two loosely coupled interfaces?

I have two interfaces: Camera and Computer. So far, each interfaces have multiple implementations in my codebase and they are loosely coupled (no implementations of Camera depends on any ...
2
votes
4answers
181 views

How to make components communicate with each other

I have a simple setup where I've decided to reduce my overall OOP design and opt for lots of small individual components that I can add and remove from a particular object. The whole point of this was ...
0
votes
1answer
111 views

Abstract Base Class decides which type of child class to create at runtime

I have an Abstract Base Class AbstractModel class AbstractModel { public: struct predictionStructure{}; virtual predictionStructure predict(CompanyLib::Matrix<double> data) = 0; std::...
0
votes
1answer
60 views

ASP.NET Core - Using Partial Views inside a Modal window for my Add/Edit/View Details screens?

I've been developing .NET projects for the past 3 years, and on my recent web .NET projects, I've been using Partial Views for all the screens that contain Forms for Add/Update/Delete or other ...
0
votes
1answer
108 views

How to expose C++ static library interface, extending Pimpl to an abstract interface

Until today I had a static C++ library with no separation between the public interface and internal headers. My other apps just linked to it, included the required headers, and used whatever they ...
-2
votes
2answers
104 views

How can we implement an incremental naming system?

Just like how Mac or Windows gives incremental names to new folders, how can we implement such a system in a database? Let's say I have currently 3 folders (default names) i.e., "untitled folder&...
1
vote
2answers
178 views

Concept/Design question: Alternatives to switch/conditional statements and Enums

I am practicing design patterns and OO concepts such as inheritance in java and I'm writing an application that represents a vending machine. I have two questions focused on ideal structure and design ...
-1
votes
1answer
115 views

Are common design patterns applicable for microservice architectures?

As part of my master's thesis, I am currently working on a framework for building microservice-based service systems. Based on my research, I am able to define important design criteria that the ...
1
vote
2answers
352 views

Are experienced developers and software architects able to describe an entire software application in terms of design patterns?

Do experienced developers and software architects see entire application in terms of design patterns? In other words experienced developers and software architects able to describe an entire software ...
0
votes
2answers
62 views

How to handle results output without cluttering code?

My Python project performs a complex set of operations, and it's important to make clear which operations it uses and in what order. Therefore, it has a main method that reads like an overview of the ...
2
votes
3answers
205 views

What is a manageable way to handle physics collisions for many types in C#?

I have a function that takes two objects and uses a switch on the enum types of the objects. The problem I have is this is getting painful to manage as I add more and more primitive types and i need ...
0
votes
3answers
151 views

Should validation logic be inside a factory method or inside the object's constructor?

Say I have a hypothetical factory method whose single responsibility is to create MyObjects. However, MyObject should only ever be constructed with an ordered list. Further, MyObjects without an ...
0
votes
2answers
149 views

Is it a good/bad practice to create overlapping types?

Here's a simple example: an API returns a list of possible options with the following structure: { "familystatus": [ { "Id": 1, "Name": "single&...
1
vote
1answer
83 views

How to implement Gang of Four's Lexi's Compositor-Composition?

I'm studying Design Patterns book and I was trying to understand the Composition principle in Lexi's Compositor-Composition as explained in figure 2.5, as well as how to implement it. Where the ...
0
votes
1answer
137 views

Is it bad practice to run different versions of code in different environments? (i.e. test, prod)

As an example, let's say you have the following pseudocode: if test environment: # meaning you don't have the typical service account prod perms sudo as service account + do operation else: # in ...
2
votes
0answers
87 views

Is there an elegant way to handle run-time dependent object composition without using dynamic_cast?

Context I'm attempting to design a modelling framework that is modular and easy to extend and test. (I'm trying to follow open/closed, dependency injection, and composition over inheritence principles)...

1
2 3 4 5
84