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
1answer
85 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
41 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 ...
-3
votes
0answers
36 views

What is the best approach to have user input whole number values while hiding the fractional part? [closed]

Our financial web application deals with the currency values where the user inputs some change value either in whole number(USD 5) / fractions (USD 5.99). This change value sometimes gets auto ...
2
votes
2answers
140 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
118 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
115 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
73 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
120 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
66 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)...
0
votes
2answers
68 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
1answer
55 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 ...
5
votes
1answer
285 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
0answers
33 views

MVP in plain JavaScript with nested components

I've been working on a system which has a number of MVP components implemented in plain JavaScript. They are instantiated from a main file and have no knowledge of each other which is great so far. ...
0
votes
2answers
49 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, ...
0
votes
0answers
62 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 = ...
0
votes
2answers
168 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
0answers
36 views

compare function pattern or architechural guidance

I'm looking for a pattern or architechural guidance. I have a type TriggerParams in which I have entity value and data type. I have to compare the entity value using a different function. so one ...
0
votes
1answer
71 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 ...
0
votes
0answers
15 views

Android SDK in memory session data storage options

I'm developing an SDK that involves jumping out of the app to others through intents and restoring of the same in memory session. The SDK is initialized using some parameters that are saved as ...
1
vote
1answer
117 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 ...
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
106 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
142 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
96 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 ...
0
votes
1answer
46 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
336 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
110 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
30 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
156 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
48 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
18 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
121 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, ...
0
votes
1answer
40 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
90 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
48 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
166 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
110 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
42 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
390 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
43 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
172 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, ...
0
votes
0answers
53 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
132 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
119 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
466 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 ...
1
vote
1answer
187 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....
31
votes
10answers
4k 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
140 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
45 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 ...

1
2 3 4 5
83