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

How to abstract version switching using feature flag?

I have two versions of an API with similar but slightly different response structure. We are currently using V1 of the API and will gradually move to V2 soon. The switch has to done using a feature ...
-2 votes
1 answer
292 views

Is this the right mechanism for 2 way heartbeat?

I have a software application where we have 2 services, say A and B. A delegates some long running work(tracked by an id) to B which is done asynchronously. They both talk via HTTP. Post submitting ...
218 votes
10 answers
232k views

What is MVC, really?

As a serious programmer, how do you answer the question What is MVC? In my mind, MVC is sort of a nebulous topic — and because of that, if your audience is a learner, then you're free to ...
1 vote
1 answer
266 views

Call library functions with varying number of inputs while keeping API simple

For a ASP.NET Core application, I'm using a library which performs calculations using objects that have a similar interface but their constructors use different inputs. The inputs are market prices ...
3 votes
1 answer
360 views

How to set up a sql database to cater for user records, group records and default records?

Outline I have an application that loads data from a database. I'm not talking about client data here though, I'm talking about application configuration. The database will therefore come with some ...
0 votes
0 answers
35 views

Design pattern for scheduling method calls (open-loop control) [duplicate]

I have an ERP-style system that needs to allow users to orchestrate an Entity.action() on a variety of objects that implement the Entity interface, at different datetimes. Calling action() would ...
0 votes
2 answers
89 views

Multiple steps of mutations in one function - how to refactor?

My application contains webhook handlers that should execute many actions when the event happens. Given CUSTOMER_REGISTERED event this is what happens in pseudocode: function WebhookHandler(EVENT) { ...
0 votes
0 answers
50 views

Design patterns for nested loop execution [closed]

I'm writing an application with a nested loop structure. Importantly, some of the iterations of each loop might be skipped if they have already been executed in the past and their results have been ...
0 votes
2 answers
92 views

Shared logic to different types

I have several services and each of these services has interfaces for each. I need to add a shared execution strategy here. By designating two classes with the same inheritance relationship as primary ...
0 votes
1 answer
106 views

What are the considerations between a class variable and a global variable

At first glance, these seem equivalent. If one has the right visibility, one can access a global variable or a class variable from anywhere in the program; There is only one, shared copy of them. So ...
8 votes
3 answers
2k views

Balance between aggregate boundaries and domain consistency in DDD

Designing an Aggregate and choosing an Aggregate Root getting tricky for me all the time especially when it comes to ensuring right transactional contexts and consistency constraints so I'm wondering ...
1 vote
2 answers
314 views

Chain of responsibility or simple dependency injection for Querying API

I am working on refactoring a project code that is wired up in a tangled way. It was started with decent dependency injection and over time with all custom requirements it looks it got tangled up. ...
0 votes
0 answers
11 views

Angular2 architecture: Sending runtime data updates to components

I have an Augular2 application which builds dynamic views built on top of a number of UX components. These views are dynamically built using a json configuration file. Each UX component has an @Input ...
2 votes
1 answer
149 views

Design Pattern: How to handle changing format of text file?

I have a text file which is evolving and thus, difficult to manage. Hence, I am going to rewrite the code from scratch. Since, only few parts of the txt file change with a newer version, from the ...
2 votes
1 answer
55 views

Allow\disallow actions in one system based on the state of another

Subj - how could I allow\disallow actions in my system based on the state of another external system (I have access to it's state via the shared DB table)? I can get the state of another system almost ...
0 votes
1 answer
43 views

Use factory design pattern to create a specific object

I am using this DTO class to pass object between web application layers public class CreateProgressDTO { public int Total { get; set; } public int Created { get; set; } public decimal ...
1 vote
2 answers
362 views

Should a UnitOfWork contain every Repository?

I'm trying to get the Repository/UnitOfWork pattern figured out. We're working on a project with EntityFramework and our DBContext contains 200+ tables. Right now our approach is to inject whatever ...
2 votes
0 answers
59 views

Best approach for several steps with user input in between

I've read several questions and I couldn't find one specifically similar to mine. I also don't think there's a design pattern for this situation as I think my system is a legacy system and don't fit ...
37 votes
4 answers
30k views

Model-View-Presenter implementation thoughts

I'm trying to get a good grasp of how to implement good decoupling between a UI and the model, but I'm having trouble figuring out exactly where to divide the lines. I've been looking at Model-View-...
4 votes
4 answers
556 views

Pattern for endpoint that routes requests?

I am building a service that will push notifications to many other services. It has a couple of different notification types that each consumer may care about, but likely will not care about all of ...
22 votes
3 answers
13k views

How should I implement the repository pattern for complex object models?

Our data model has almost 200 classes that can be separated out into about a dozen functional areas. It would have been nice to use domains, but the separation isn't that clean and we can't change it. ...
0 votes
2 answers
131 views

Refactor to object oriented style and use design patterns

I have an application that has been written in Python and it is used for generating various MIS reports for a specified month. It is now written without using the OOPs concepts or any kind of design ...
2 votes
3 answers
5k views

Extending a struct. Using helper classes rather than composition

I have a struct which I want to add static methods to. Yes, you guessed right I'm talking about Datetime. It's a pretty typical requirement to add MyCustomParse. It happens to return Datetime?, so it'...
1 vote
3 answers
1k views

How Design a program that must handle multiple "products" like in a production line

I have some problems figuring out how I should design an application. On a production line there multiple stations. The products will move from one station to the next. Each station will execute some ...
3 votes
1 answer
277 views

Best way to refactor service with too many dependencies

We are creating the backend for a web app using a sort of layered architecture. The service layer is supposed to handle the business logic and passing data to the repositories. This service layer is ...
0 votes
2 answers
166 views

Coffee machine strategy pattern implementation

I came across an article about LSP https://stackify.com/solid-design-liskov-substitution-principle/ . It seems that a strategy pattern could be implemented here but I cannot see how to implement it. ...
6 votes
3 answers
2k views

Loose Coupling Presenter to View in MVP

We work in a Java shop here and our web application uses an implementation of the MVP architectural pattern. Our manager comes from a .NET world, where he has been exposed to the MVVM design pattern. ...
0 votes
1 answer
91 views

Where to create repository instances?

I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
7 votes
5 answers
10k views

How to solve cyclic dependencies in a visitor pattern

When programming at work we now and then face a problem with visitors and module/project dependencies. Say you have a class A in a module X. And there are subclasses B and C in module Y. That means ...
0 votes
1 answer
59 views

Middleware with parameters and dependencies

I'm trying to use the middleware pattern to avoid repeating same code over and over again. In my application I work with user data a lot, therefore there are a lot of checks here and there. The ...
0 votes
1 answer
274 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 ...
2 votes
0 answers
191 views

How to to log clicks for a Pay-Per-Click software?

Let say you have a Website with advertising, and each time a user clicks on it, you want to charge an advertiser the amount he bids (basically, a pay-per-click system, like Adswords, with a different ...
1 vote
1 answer
144 views

State Pattern when the Behavior in Object of Type A is Dependent on the State of the Object of Type B

I have used the state pattern for my web application where a user can be in one of three states: activated, required_activation and suspended. I have created 3 states classes as given below (source is ...
0 votes
3 answers
209 views

Design pattern for feature toggling

To simplify the domain let's say we have a system that takes in orders from customers. There's an API endpoint that validates the input, and if valid pushes the order onto a messaging queue to be ...
0 votes
3 answers
126 views

Java Library - How to do Pure Dependency Injection When State is a Factor?

To set the stage, I am trying to do pure dependency injection for a Java Library I am creating to make it more testable. As it is a library, I want to do pure dependency injection without creating a ...
3 votes
1 answer
230 views

Data processing pipeline design for processing data

I have a use case for which I need to build a data processing pipeline Customer contact leads data coming from different data sources like csv, data base, api has to be first mapped to a universal ...
-1 votes
2 answers
110 views

Appropriate design pattern for coupled Objects

I code an Object-Oriented simulation where you can have a Unit move on a Terrain. The cost of such move depends both on both Unit capabilities and Terrain features: a boat can move on water, a plane ...
0 votes
1 answer
75 views

am I understanding MVVM correctly? [duplicate]

ViewModel has Two-way data binding with UI which means UI can access the data from ViewModel and can update the view models data. The Model has one-way data binding and is only supposed to respond ...
4 votes
5 answers
4k views

Pattern to detect when all but one reference (in a managed language) are destroyed?

In my application I have a class, and each instance of this class shares part of an unmanaged resource. Sharing is facilitated by a manager object. When an instance is destroyed, the manager should ...
51 votes
7 answers
21k views

Why is chaining setters unconventional?

Having chaining implemented on beans is very handy: no need for overloading constructors, mega constructors, factories, and gives you increased readability. I can't think of any downsides, unless you ...
0 votes
1 answer
175 views

Writing Event Process architecture for multiple event handler interfaces

I am working on Java program which will listen multiple kind of events from multiple sources and store information to multiple sinks. Each interface will have its own source to listen and own sink ...
25 votes
4 answers
4k views

Do named arguments replace the builder pattern?

When using a language that supports named and optional arguments, does the builder pattern no longer have a practical use? Builder: new Builder(requiredA, requiredB).setOptionalA("optional")....
0 votes
0 answers
36 views

Pattern For A Load Behavior That Can Act On Any Class

I have a class called ContentLoader. This class has one method LoadContent<T>(T model, int?loadLogicDecider1, int? loadLogicDecider2, etc). It runs through the input class looking for a ...
0 votes
3 answers
179 views

How to handle subclasses needing different method signatures for the overriden function?

I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, ...
1 vote
1 answer
127 views

UML Composition parent multiplicity

The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent. However, given that: a ...
1 vote
1 answer
180 views

Check if a controller is doing too many things

There is REST endpoint in my application which handles POST request and then makes a HTTP post to another external application and when the resource is creating in the external resource then I create ...
1 vote
2 answers
141 views

Maintainably converting flowchart ideas to an architecture

My team is communicating proposals for the interaction of several processes as a flowchart. I've been drafting a codebase architecture we can use as a starting point. There are two ways intended ...
0 votes
1 answer
794 views

The finer points of HMVC

I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
2 votes
1 answer
126 views

The notion of configurable strategies

I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore: The input is a scalar and a ...
3 votes
3 answers
2k views

Design pattern to force client of a class to call a method

I have a large class with complex properties. I'd like to introduce a default implementation, allow the user to override part of the default implementation and also make sure the user calls a sync ...

1
2 3 4 5
86