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
8
votes
5answers
2k 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 ...
2
votes
2answers
162 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&...
0
votes
3answers
197 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 ...
-1
votes
2answers
106 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 ...
1
vote
1answer
178 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,...
2
votes
5answers
407 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), ...
0
votes
1answer
114 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
0answers
37 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
1answer
176 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 ...
0
votes
1answer
85 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 ...
0
votes
0answers
69 views

How to draw internal patterns used by the Spring boot framework in UML class diagrams?

I am currently in university and doing some practical work as a module. The professor demands that we work with the waterfall model and we are currently in the design phase. The requirements for the ...
1
vote
1answer
153 views

Rock Paper Scissors with Visitor Pattern

I've been going over the Visitor Pattern to try to understand it. Is this a correct implementation of the Visitor Pattern for RPS?? Here's the implementation code: public enum ResultEnum { WIN, ...
1
vote
1answer
46 views

Designing for many third-party REST API integrations

Not sure if this is the right forum for this, but I've come across a need for this pattern a few times lately, and I would love to get some opinions on options for how to handle it. Say I have an app ...
0
votes
2answers
537 views

Order Management Microservice design pattern

I have question on how to design an order management microservice. An order has different workflow based on the previous state or based on the business needs. I'm guessing at some point cannot keep on ...
-1
votes
1answer
86 views

Design pattern to sync local databases with the cloud [closed]

I would like to find the best way to solve the following problem: I need a database for a software. The software needs to use the data to populate the UI and allow the user to interact with them (edit,...
3
votes
3answers
327 views

Undo/Redo with Command Pattern and Object Destruction

I'm developing a Command Pattern with Undo/Redo support. The environment is Unity C# but should be mostly language-agnostic. My initial commands comprise of adding and removing objects to and from a ...
2
votes
2answers
156 views

Exposing methods for polymorphic children from the aggregate root

Consider the following fictitious toy example: There is an aggregate root DayChecklist that holds a list of Tasks planned for the day: class DayChecklist { String id; DateTime today; ... ...
0
votes
1answer
49 views

How are discriminated unions (e.g. in TS) used in messaging schemes?

In the documentation about discriminated unions in typescript, here it says: Discriminated unions are useful for more than just talking about circles and squares. They’re good for representing any ...
6
votes
6answers
465 views

When are equality comparisons between IEEE 754 floating point values acceptable?

My understanding is that it's rarely a good idea to compare two floating point numbers due to inherent inaccuracies. However, my understanding of those inaccuracies are that they are deterministic and ...
0
votes
0answers
151 views

Should I run validation logic on the DTO or the entity model?

Suppose I have a Controller that takes a DTO that represents an Order. This DTO has inner DTOs that could potentially have entity IDs and/or entity data that's used to create an entity dynamically ...
2
votes
2answers
232 views

What methods can be used to simplify mathematical expressions?

For fun, I would like to design a mathematical expression evaluator, with variables. It could simplify the entered expressions by factoring them, reducing them to a sum of simple fractions, ...
-1
votes
1answer
118 views

Handling multiple events in Event Driven Architecture

Let's say I have Service A that publishes Message 1 to be processed by Consumer A The same service A that publishes Message 2 to be processed by Consumer B I need to make sure that consumer B ...
2
votes
1answer
141 views

Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes' method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case ...
0
votes
1answer
249 views

C# is it acceptable to create a generic class and use an enum as generic type?

Abstract The case: Application contains a lot of views with a list of data. Data views (lists of records) have pagination, filtering and sorting options. The user must be able to select a "...
6
votes
4answers
507 views

Is there a standard name (or examples) for the "sandwich" pattern?

I've noticed a certain idea recur in different contexts, but before I start calling it "the sandwich pattern", it would be useful to know (in the spirit of other "Is there a name for ...
2
votes
1answer
527 views

How to do MVC in C++

I have a QT application with a window of OSG written in C++. I want to implement the app using MVC design. The application allows you to add markers to OSG model and it is using QT to edit the markers....
32
votes
10answers
5k views

Does logging inside a class violate the SRP?

I wrote a class that takes a Logger class as one of its arguments: class QueryHandler: def __init__(self, query: Query, logger: Logger) -> None: self.query = query self.logger =...
0
votes
1answer
165 views

Design pattern for two inputs?

First of all, I had task 1 and it was about rest API, requesting calls using httpclient in order to use the functions of an API. We get an input from a user, either "Online" or "Offline&...
0
votes
0answers
53 views

What's the proper way to avoid long parameter lists? [duplicate]

If I architect to utilize use-cases then I soon arrive at long param lists. As an example: class MainViewModel @Inject constructor( private val getUsers: GetUsers, private val deleteUser: ...
0
votes
3answers
98 views

Summarizing actions of a web application and serve it as only one email rather than many

I have a web application that has a lot of multi-action items that are done that require an email notification. Although not the biggest deal, we currently have it set so that it sends an email to the ...
0
votes
0answers
52 views

Fetching data in separate servers

I have a monolithic REST API and a separate WebSocket server that’s used for real-time updates. They're both separate so that I can scale them independently. The API fetches data from the database and ...
0
votes
1answer
151 views

Best practice to create model objects in Java

I have an existing microservice that talks to a Natural Language Processing (NLP) product and fetches around 50 fields. I need to create domain objects in Java now from these fields. I read about ...
0
votes
3answers
174 views

Ingest data from our partener : API POST vs Event Driven Architecture

I am in the process of carrying out a software architecture for my client, in fact THE HISTORY OF THE REQUIREMENT : MY PARTNER SEND cvs files via MFT to MY CLIENT , many times a day . MY CLIENT has a ...
4
votes
4answers
136 views

Approach to keep collection of parent entity sorted when child changes?

Assume a Person has a Phone and a Phone has Contacts. Assume in the real world the Contacts of a Phone are sorted by their first name. When I phone.add(Contact c), the phone sorts its contacts. Then ...
0
votes
3answers
221 views

Refactor SLA problem of high level code inside if/else?

I have some code where I believe the SLA (single level of abstraction) principle is broken in a way that the low-level code (if-statements) is outside and the high level code is nested inside the ...
2
votes
1answer
133 views

How can I enforce that decorator pattern is complete at compile time?

I have a C++ class (Class D) that is a decorator of another class (Class B). Class D inherits from B and also requires an instance of B to construct that it keeps track of. Class D overrides all ...
1
vote
1answer
78 views

What is the granularity of the SRP of functions? [duplicate]

If a function is being used to process incoming results, I believe an SRP violation exists if it contains all the logic: def process_response(response): '''Process the results of the web request''' ...
0
votes
0answers
41 views

How to design Stateless Application in Spring with Redis

When we write classes in Java it says combine business logic with data, ie the functions and variable should live together in a single class. but now when we use spring we have something called a ...
4
votes
3answers
835 views

What about Utility-Classes, but without hard dependencies?

The average utility class: A stateless class that provides some functionality by exposing static methods. Its default constructor is private to avoid instantiation. When ever the average utility class ...
1
vote
2answers
112 views

Designing UI module for an application

I have an UI module that will expose only one class - UserInterface. The class will be responsible for collecting user input and providing output (command line UI style). From logical way of thinking, ...
0
votes
2answers
151 views

Which design pattern to use to make a mix of in-sequence and parallel HTTP calls?

We have to make a bunch of HTTP calls from Java/Spring-Boot application which will be mix of in-sequence and parallel. Level 1 : We make 3 parallel calls to Services 1 , 2 and 3 Level 2: After service ...
0
votes
2answers
146 views

Design: Tying behavior to state

I have the following (hypothetical) setup and am wondering if anyone has design suggestions, keywords, or nudges. I have a class Walk that implements a method doActivity. This method keeps track of ...
2
votes
1answer
99 views

Visitor pattern applicable ? - Applying rules to a list of registrations

I have a list of Registration's, on which I need to apply a set of rules to each individually. Rules can be a single Rule, or a sequence of rules, representable by a tree. One rule is a ...
-3
votes
2answers
82 views

What design pattern / class / interface should I use for encapsulating a program? [closed]

I am building a chess - related application, and I want to use a pre-compiled program called Stockfish as my chess engine. I am wondering what is the best practice to encapsulate the usage of the ...
10
votes
4answers
2k views

Can a class contain its own class?

Suppose I have the following class structure: A forest can have any number of trees, but each tree can belong to only one forest. If the forest is deleted, the tree is deleted. A tree must have at ...
0
votes
0answers
40 views

Mediator design with a circulator dependency

My project is web related, and the intent is that I am decoupling two pages worth of actions so that each class would have a list of actions on their page, and if any action so happens to navigate to ...
-2
votes
1answer
69 views

How to implement factory pattern in following case?

I have a program which downloads web pages and then scrapes html to create domain specific collection objects e.g. ProductCollection, CatalogCollection, NewsCollection and more. The idea is to create ...
2
votes
1answer
116 views

Rust design when object needs to query outside data for some uses

I am modeling a ship that has contracts. Each contract can either be a fixed rate contract which pays a set fixed amount every day or a market index contract which pays an amount that varies based on ...
2
votes
2answers
313 views

Difference between facade and orchestrator in the context of microservices

Suppose we have 2 microservices - service A and B. These two services are independent for most parts and API client talks to them directly. However, their functionality overlaps or intersects in some ...
1
vote
1answer
104 views

Is the Target interface really necessary in adapter design pattern?

I saw a code example online that uses adapter pattern as: if you look at the HR system, the employee information in the form of string array and the ProcessSalary method of the Third Party Billing ...

1 2
3
4 5
85