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
46 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
-1 votes
3 answers
187 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 ...
  • 117
0 votes
1 answer
145 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 } } ...
  • 387
0 votes
1 answer
56 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 ...
  • 149
-1 votes
1 answer
362 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
2 answers
448 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: ...
  • 387
0 votes
6 answers
434 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 ...
  • 17
0 votes
3 answers
188 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
2 answers
140 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 ...
  • 231
1 vote
1 answer
155 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
0 answers
37 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 ...
  • 1
2 votes
1 answer
218 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 ...
  • 131
-1 votes
1 answer
122 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 ...
  • 11
3 votes
2 answers
280 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
1 answer
258 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> ...
  • 99
1 vote
0 answers
63 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. ...
  • 83
0 votes
0 answers
68 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 ...
  • 155
2 votes
4 answers
208 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 ...
  • 2,010
1 vote
1 answer
122 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
1 answer
282 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 ...
  • 1
0 votes
1 answer
446 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
2 answers
138 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&...
user avatar
1 vote
2 answers
346 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
2 answers
244 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
2 answers
370 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
2 answers
74 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 ...
  • 111
2 votes
3 answers
212 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 ...
  • 2,010
0 votes
3 answers
538 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 ...
  • 155
1 vote
2 answers
181 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&...
  • 121
2 votes
1 answer
115 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
1 answer
179 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 ...
  • 103
2 votes
0 answers
94 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)...
  • 29
0 votes
2 answers
86 views

Why doing more than one thing in a class is sometimes valid? [duplicate]

classes and method should do one thing like the code below: class A { public int a() { b(); } private int b() { c(); } private int c() { } } The code mentioned below I found it ...
0 votes
1 answer
138 views

Best practice or patterns to couple complex custom objects to custom logic

In many project that grow more complex at a certain moment business rule editors, workflow editors, custom taxonomies and such enter the arena. In all of these a coupling is made between a complex ...
  • 544
5 votes
1 answer
334 views

Methods with "With" prefix?

I started working on a project and I saw some methods with this With prefix and I'm wondering if this refers to a known pattern. Does anyone know of this naming pattern?
0 votes
2 answers
72 views

Do I need a Message processing service before RabbitMQ (or any other message broker)

I hope that's a proper place to ask my question. I am wondering how is best to integrate RabbitMq (or any other message broker) into my project. There are 2 options: Simply collect all messages, ...
  • 103
0 votes
0 answers
75 views

Download method of type void vs response

Given a method that is widely used and has a void return type: from somepackage import download_model from somepackage import get_filename def download(name, download_path): response = ...
-1 votes
2 answers
875 views

Clean Architecture, good approaches to avoid hard-coding the creation of entities on the Use Case

I have an Use Case that has an UseCaseInput (which is a parameter object of the use case) and an UseCaseOutput which is the output object, the UseCaseInput has lots of parameters in which will be used ...
-1 votes
1 answer
144 views

Other than the intent, is there a difference in how you implement Chain of Responsibility and Decorator Pattern?

I think it's fair to say that they are quite similar to each other. The only difference that I know is the intent. Chain of Responsibility: Avoid coupling between the sender of a request to its ...
1 vote
1 answer
140 views

Asynchronous HTTP request pattern

Here is the pattern that I thought about for a resource accepting a single asynchronous HTTP request at a time (i.e. a request which has not yet been fulfilled when the response is sent): Create a ...
  • 570
8 votes
5 answers
3k views

Interface implementation where one method body remains empty

I have producers that take data A, produce data B and send it public interface Producer<T>{ void produce(T data); void flush(); } public class DataBaseProducer ...
  • 231
2 votes
2 answers
491 views

Factory pattern where some classes require additional paremeter(s)?

We have multiple publishers, that publish the data somewhere. For example, we have ElasticSearch publisher, AWS S3 publisher, or file publisher. Now the interface looks like this interface Publisher&...
  • 231
0 votes
3 answers
370 views

Is it an anti-pattern to extract common configuration code as a library and reuse it across microservices?

Is it an anti-pattern to extract common configuration code as a library and reuse it across microservices? I am breaking down a monolith app into a few of microservices. What I stumbled upon is: since ...
  • 27
-1 votes
2 answers
209 views

Hide private class member details from user but use it internally in non user facing code

I find myself in a situation with the following implementation. I have a class that is exposed to users. My intention is to expose a high-level abstraction to the user rather than internal details of ...
  • 135
1 vote
1 answer
371 views

Memento pattern for Undo/Redo AND Save/Load with multiple objects

In a pretty big project, I have a hierarchy of objects, let's say: Zone object, which contains Block objects and Connection objects. Mainliy, the Connection object links together several Block objects,...
  • 121
2 votes
5 answers
658 views

How can I write an enum for date periods where not all periods have a static number of months?

I have an enum that works very well to represents date periods and the number of months in those date periods: public enum StandardDatePeriod { ONE_MONTH(1), SIX_MONTH(6), ONE_YEAR(12), ...
  • 285
0 votes
1 answer
122 views

Should i overwrap functions to maintain Single Responsibility for code organisation? [duplicate]

I am trying to maintain proper code organisation for my codebase. I came across a situation whereby organising my code into class A, B, C is unnecessary as class C can be incorporated into class A and ...
0 votes
0 answers
45 views

Which Design pattern (C#) should I use for binding / mapping unrelated models and data contracts and for service using them? Code sample below

New Design: We are porting Legacy code to C#. We have Request and Response Data Contract for each set of Business Data. These are POCO generated using Schema of External vendor. We will be creating ...
6 votes
1 answer
230 views

Should operations on properties of list objects be encapsulated in a domain class that wraps the list?

I have a list of product price objects, List<ProductPrice>. @Value public class ProductPrice { Long id; LocalDate startDate; LocalDate endDate; BigDecimal value; } From ...
-1 votes
2 answers
330 views

Consuming Multiple resources from a single REST Service

I am developing a Spring Boot Application which consumes another REST service to get the User's Account information. The same service provides multiple operations like: GET: /userid/retrive -to get ...

1 2 3
4
5
86