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
39 views

Passing object or using the field

I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class? Using the field: ...
0
votes
1answer
59 views

Should there only ever be one instance of a ViewModel object?

Assume a rather simplistic model: class Person{ static List<Person> LivingPersons String Name List<Person> Dependents } From this it can (hopefully) be seen that a single ...
0
votes
1answer
64 views

Pattern name to compare previous raw values to current values

I find myself applying a certain pattern again and again and I assume I am not the first one. I am looking for a name. In the environment I find myself in we get updates to values via an external ...
4
votes
2answers
108 views

GoF Builder Pattern Applicability

The book Design Patterns: Elements of Reusable Object-Oriented Software says to use the builder pattern when The algorithm for creating a complex object should be independent of the parts that make ...
0
votes
1answer
66 views

Chain of responsibility look alike but choose handler at runtime

currently I have an structure of PopUps and I've been thinking to use Chain of Responsibility pattern, but the difference is a popup can back to previous one PopUp and also can go to any other PopUp. ...
0
votes
1answer
62 views

Python: Function pipeline with multiple return/input values, or use OOP? Best Practices?

I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways. Looking for the best practise on ...
1
vote
0answers
59 views

Visitor pattern with internal iterators

I'm trying to understand the following description of implementing the visitor pattern with an internal iterator. It is from the GoF's Design Pattern Elements of Reusable Object-Oriented Software book ...
0
votes
0answers
64 views

Can someone suggest what pattern I used mistakenly and is it correct in this situation. Any alternative?

Client_1 uses --> IService_1 and thus Service1_impl public interface IService_1 { void DoTask_1(); } public class Service1_impl : IService_1 { private readonly IDepService_1_v1 ...
2
votes
1answer
231 views

What is the name of this pattern / style?

We have a "workflow orchestration" system at work. It works something like this: You configure what to run (in a database table), such as: NameOfStepATHingToRun ="weather_data" ...
-2
votes
0answers
18 views

Naming polymorphic class for branching similar to Command

I was refactoring bunch of if-else branches to polymorphism. Basically I am branching based on command string, then I deserialise from json data object (different commands have different data ...
0
votes
0answers
23 views

Design pattern for intercepting requests to an API (Rule Engine)

I want to use a rule engine to centralize business rules. My rules require information not typically owned by systems that call the rules engine. I don't want to complicate these systems (System A and ...
1
vote
2answers
81 views

Good OO design pattern for variant return type needs

I've got a validation function something like this (pseudo-code): public function validate(Thing thing) { if (thing.a != "a") { return false; // most of the time } if (...
1
vote
2answers
83 views

Visitor design pattern usage

I have been implementing a software driver for an external (from my microcontroller point of view) chip communicating with my microcontroller over I2C. From the higher perspective the chip is a ...
0
votes
1answer
62 views

How can I orchestrate multiple business tasks?

I have a WebApi backend with a Blazor WASM frontend. The application is split up into 3 main parts. Core, Infrastructure and Presentation. Basic onion architecture structure. Core.Domain Domain ...
1
vote
1answer
120 views

Why we don't use array of classes instead of Chain of Responsibility technique

I am new to SE. Recently I read about the Chain of Responsibility pattern, so basically what it does is: it creates a class that has some methods and also next class (next chain block), so when it ...
-2
votes
2answers
76 views

How would you create abstraction for event holding only Ids - references to other objects

class DomainEvent { } and then I have different events with following structure: class SomeEvent extend DomainEvent { private UUID orderId; private UUID orderlineId; private UUID productId; ...
-2
votes
1answer
133 views

toppings in pizza factory?

Going through Head First Design Patterns, and their Pizza factory example, it seems that there is no room for specifying toppings. In general, if I have a process which contacts different APIs which ...
0
votes
1answer
41 views

ORM patterns: entity properties that depend on collection loading

Given a couple of entities, Invoice and InvoiceRow, I want to calculate the total amount by summing up each row's amount. public class Invoice { [Key] public int? Id { get; set; } public ...
0
votes
1answer
135 views

Machine Learning pipeline design patterns

In machine learning we have modules that perform operations on data in a sequencial manner. Modules are generally the following: Data Collection Module: Takes raw data from a resource (filesystem,...
-2
votes
1answer
45 views

Best practice: keep DB models in one file or split into modules?

I've a Python project with ~30 SQLAlchemy models and I'm not sure where they belong. All models belong to the DB but also to a module, so I'm not sure about the right namespace. Here are some ideas: ...
0
votes
0answers
34 views

What is best approach to designing a local-to-cloud cloud-to-local Infrastructure?

I plan to have a cloud web application(CWA) and several local web application(LWA), let's assume 3 LWAs and 1 CWA. CWA === LWA. This web application would consist of a database server, file storage ...
0
votes
2answers
66 views

Patterns for returning messages/results from business logic to UI

Cross-posting from SO. Is there a name for the patterns used send messages/errors and results through an application's layers from business logic/database to the UI? What is the modern way? For ...
-2
votes
0answers
36 views

How to divide a big service-class and how to choose good names for the divided results

I have a Service-Class or an idea of lot of methods, which i could package into one Service-Class. As example let us take 100 methods. But i dont want to use one big service class, but more. So i take ...
0
votes
1answer
67 views

Monolithic view model MVC

Currently working on a legacy app. One section deals with generating "reports", each which share some common subsections, that are based on strongly-typed razor partial views. The largest ...
5
votes
2answers
193 views

DRY polymorphic object creation (always valid)

Assuming we have polymorphic entities such as the following, with constructors enforcing invariants (assume there could be lots of sub-classes). What would be an effective/elegant approach to ...
5
votes
2answers
69 views

Design pattern for completing missing fields of an object based on fields provided

I am developing an application that needs to programmatically determine the complete state of a DC motor, given a limited number of details about the state. For example: { voltage: Measurement(12, &...
2
votes
1answer
113 views

Serialization and SOLID principles

I have several configuration structures that can be JSON serialized and deserialized as follows: namespace config { struct Foo { std::string hostname {}; std::string ip_address{}; ...
2
votes
3answers
202 views

Design patterns to handle multiple file formats and versions

I've read both visitor&strategy patterns are a good choice when it comes to export data into multiple file formats. I'd like to understand how to apply both so I've created a really simple dummy ...
0
votes
0answers
40 views

Design Patterns for an Interaction Heavy App

For an app like Figma, for example, how do engineers deal with the various states a user can be in? A user can select an element. This element is now surrounded by a thin blue line to indicate it was ...
0
votes
3answers
155 views

How to model and unit test code with multiple side effects?

How to unit test code that requires multiple side effects? For example, making an invoice. Simple action requires few thing to happen simultaneously: create invoice in db send invoice to backend ...
0
votes
0answers
62 views

What design pattern is Python's PEP 451 implementing?

PEP 451 provides a mechanism to change what is actually loaded when someone uses import in Python. After reading PEP 451 and using it in one of my projects I thought that this was an implementation of ...
1
vote
1answer
66 views

Proxy / Decorator Design pattern scalability to a lot of methods

I'm trying to solve a common problem of logging each method that calls 3rd party operation and I don't understand how to scale it up. Current implementation: public class ElasticsearchClient { ...
0
votes
1answer
27 views

Sending multiple calls from angular application

I am working in Angular project which is connected to REST API. Here we have an endpoint to create and update room types. POST endpoint for create and PUT endpoint for update exiting room types. Both ...
0
votes
2answers
53 views

Design of DTO-Objects for an API with dynamic table design

We have a table design in our database to dynamically store settings: You wouldn't need to understand every column in the table but basically tbl_Setting defines all possible settings and ...
2
votes
2answers
90 views

What does abstraction mean in Bridge design pattern?

The bridge pattern is defined as 'The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently'. I get that abstraction here doesn't mean abstract class /...
1
vote
1answer
128 views

What is the currently best C# implementation for a Producer/Consumer scenario?

I have a relatively simple task where I need some 10 consumers to consume work to be produced into a queue, continuously. This is my first time implementing this design pattern, so I have been ...
4
votes
2answers
93 views

Separation of data retrieval and processing in loops?

Often I need to get some data and process it in some way. For example getting a list of customers from an API and assemble some summary data on them. As an example, getting : api_result = api.request(...
4
votes
2answers
119 views

How do I trigger conditional post processing action without violating SRP?

I have a User Model as below, this Model class is in the shared library. class User { private long userId; private String email; private String userType; private long departmentId; ...
0
votes
3answers
82 views

How do you structure components to objects so they are more decoupled and non dependant?

I want to setup my objects to be composed of components that can be added and removed so I have more flexibility in how I set them up. A simple example would be some object that can have components ...
-1
votes
1answer
40 views

ASP.NET Web API - what is the design pattern?

In Visual Studio, ASP.NET MVC project template is designed for MVC pattern, but what about ASP.NET Web API project template? I know that we can create API from MVC project, also we can build MVC app ...
0
votes
0answers
46 views

How to best design this communication module/library?

Introduction A customer of ours has embedded products with sensors and actuators. Now they would like to connect this device to the cloud so they can remotely monitor and configure it. It should ...
0
votes
0answers
43 views

Design an extensible permissions model in database

I’m trying to model a system with Users, Permissions and Products. The main goal is to have a way of checking if a User has a specific Permission in order to allow or deny other system operations. So ...
-4
votes
4answers
91 views

Disadvantage of the strategy pattern and how to overcome it

An often quoted disadvantage of the strategy pattern is: The application must be aware of all the strategies to select the right one for the right situation Why is this a disadvantage and what can ...
1
vote
1answer
154 views

Is this correct adherence to Liskov Substitution Principle?

I used to have a base object with subtypes behaving in all but the same way -- the difference being in their render methods. This base class defined a default render method, overridden by Some ...
3
votes
1answer
60 views

Chain of responsibility for a single instance?

I have legacy code and it has a function called initialize and this function calls N amount of methods of same object and these methods are responsible for validating identity of personas. At each ...
1
vote
1answer
61 views

Should I use ROA or SOA for a distributed application and how could I implement REST If using ROA

For my final year project I'm looking to build a distributed version of a popular benchmarking client (this has already been done using various methods involving some form of existing frameworks), I ...
0
votes
0answers
22 views

Design pattern for duplicating lines of code in control structures [duplicate]

on my website I have a multi-page form where user can pass some data on each view, but user can also save a draft on specific step(in my example 1-4). My service has a dispatch method. Based on step(1-...
3
votes
1answer
58 views

ASP.NET MVC Caching of ViewModels

My question is regarding caching and ViewModels in ASP.NET (Core) MVC. I have a service which injects a Repository<T> which is used to fetch domain models from the database. The service layer ...
1
vote
2answers
90 views

Creating an interface that connects to different data sources

I am working on a project which connects to different data sources and fetches data. The problem is each of these data source needs different parameters to fetch the data s3 = S3(ACCESS_KEY, ...
4
votes
2answers
796 views

Is there a name for this construct with generics?

I wrote this valid piece code, which made me wonder if there was a name for it: public class GenericObject<T> { public T Obj { get; set; } } public class DerivedClass: GenericObject<...

1
2 3 4 5
81