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
-2
votes
1answer
100 views

Patterns for multi tenant systems [closed]

Ok so first I want to describe the anti-pattern anti-practice. Company creates system for customer number 1. Then customer number 2 comes along they fork the codebase customize it. (Say for variations ...
0
votes
0answers
30 views

Multiple external API calls and only one valid response depends on the parameters value

In my microservice I need to call several external API. The problem is that I do not know which of them to call to get a proper response, but I am sure that one of them return a successful response. I ...
0
votes
1answer
179 views

Discount calculation pattern

I am implementing a discount calculation model. One item PER order. I do have a Product class: public class Product { public string Name { get; set; } public Size Size { get; set; } public ...
1
vote
0answers
61 views

What is a good design for accumulating temporary data stemming from several processing runs?

I would like to compute cycle times for some manipulator movements. These movements consist of different phases. I have a class that models these phases and this is its constructor to give an idea: /**...
0
votes
2answers
38 views

Should my DenyQueryException extend a exception in a DAOException or Exception

need some advice...I am fully aware that Validation/Syntax Checking, etc. should happen above the Data Access Layer. However the powers that be would like the DAOs to do an extra check. Should when ...
0
votes
2answers
119 views

Should I declare motivation when commenting? [duplicate]

When commenting code, which of the two approaches considered good practice? Explain the content of the code, "translate" it to human - readable language, but not provide any explanation ...
-2
votes
1answer
46 views

Inheritance and domain-specific logic loses its independency?

Im sorry in forward, Im sure I wont be able to express myself well. Its a game system: abstract class GameType { private $score; public __constructor($score) { $this->score = $...
0
votes
1answer
157 views

Is it ok to Inject a whole object instead of only the dependencies

I'm working with the Dependency Injection Pattern in Unity3D (an engine which uses MonoBehavior, a class that doesn't have a constructor, as the base class for all of its game components), and I ended ...
-2
votes
1answer
56 views

Unexpected shutdown before a saga completion

Suppose we have some microservices and a saga will run to do a transaction in 6 microservices. What if the whole system dies(unexpected shutdown), on middle of saga process in the step number 4?(...
4
votes
5answers
232 views

How to fix a pair of tightly coupled classes that store references to each other?

I have the following situation: class User { public Thing curThing; } //each thing can only belong to one user at a time //And vice versa class Thing { ...
-1
votes
1answer
65 views

Making a GUI for receiving/checking user input - how to arrange GUI and validation checks

Sorry if my question sounds general, I'm new to GUI and frontend/backend ideas and all that (mostly I just do scripts for math hw and such) but I make it more specific here. I have a program that runs ...
40
votes
1answer
3k views

How to design a REST API that can “prompt” the client about long-running operations?

Say you were to develop a REST API that provides access to a set of complex, long-running, operations. The typical paradigm for an API like this (as I understand it) usually involves (the client) ...
2
votes
2answers
119 views

Should base class include unused properties of sub class?

I was looking at the angular documentation and noticed this code: export class QuestionBase<T> { value: T; key: string; label: string; required: boolean; order: number; controlType: ...
3
votes
1answer
625 views

How to handle errors from back-end in front-end and different languages?

I have a rest api and a reactjs front end, in some cases, the api will send an error to the front end and I need to display that error. My app will support multiple languages, so the error must be ...
0
votes
0answers
30 views

When designing an API in Javascript with closures, should I provide singletons or factories for directly creating objects to clients?

I'm designing an API in Javascript part of an Angular with typescript project. I have involved later in this project implemented. There is a DataStorageService which I checked from git logs that ...
-2
votes
2answers
58 views

How to design a flexible multi-criteria prioritization?

Let's assume that we have a set of valid results, ex. Fruits: "Apple, Banana, Kiwi, Pear, ...". (In reality, it’s not fruits but complex objects) Now we need to pick the best result ...
0
votes
3answers
135 views

How to choose between these different options for communicating between objects?

I have a few objects that should communicate between each other. I also want to have my code unit tested. I am questioning how I should handle their communication: Should I make one instantiate the ...
2
votes
1answer
88 views

Converter implementation in Python: class versus module?

I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more. Stubs look something like this, with ir ...
0
votes
1answer
77 views

Could a getState() method in a Caretaker violates Memento Pattern?

I have looked at several examples for implementations of Momento on the web. I wonder if it is correct to retrieve the status of Originator, since this is much more accurate, up-to-date and reliable? ...
0
votes
0answers
36 views

Decouple presentation agnostic parts of the composition root from the application's entry point

Disclaimer: The technology I had in mind when thinking about and formulating this was .NET Core MVC. I was also thinking about using e.g. Simple Injector to integrate with .NET Core. That way, I don't ...
-1
votes
1answer
115 views

How to implement DAO design pattern?

I'm trying to learn how to implement a DAO design pattern (for a game, but this does not really matter). In my program, I have a database layer which has user objects. Then in the code, I have a DAO ...
3
votes
5answers
244 views

Applying function to file line by line or read entirely into structure first?

I've often found myself with the need to develop tools that process large files over a network and perform an operation to every element in that file. An element may be an individual line or an object ...
1
vote
1answer
146 views

Factory Method Pattern - the problem and what does it do to solve it

I always had problems in grasping the full benefits/motif behind using the Factory design pattern (for this post, I will stick to Factory Method pattern, specifically). True, there are (really) lots ...
0
votes
1answer
83 views

CQRS for avoiding heavy joins

I've been wondering about what is a perfect use case for CQRS where the benefits overcome the complexity and the cost with come with the package. So for me to better understand it, I want to share ...
2
votes
2answers
107 views

Builder Pattern: Is there any advantage of having instance variables + product reference instead of just product reference?

Consider the product class: class Car { private String color; private String model_num; //getters and setters for the above fields } Consider builder class 1: class CarBuilder1 { private ...
1
vote
1answer
68 views

Can I use singleton in a Flyweight factory and still be a valid GoF implementation?

For teaching purposes, I am trying to create a "something useful" example of Flyweight pattern using PHP. My idea was load some "intrinsic" data from a csv (link) to a pool and ...
2
votes
1answer
95 views

C++ instance configuration pattern via lambdas

I've been using a "pattern" to configure C++ class instances via lambdas for a while now and I am looking for: an original source & name (I think I read this somewhere, but can't find ...
0
votes
0answers
40 views

Architecture for Data Pipeline (ETL) on GCP

I want to create a Data Pipeline on GCP, after a lot of research I decedide to use Pub/Sub to send the data and Dataflow (Apache Beam) to subscribe to that Topic in Pub/Sub and save the data in the ...
4
votes
1answer
98 views

MVC Patterns: Is There a Design Pattern For Returning Lists (Arrays) of Complex Entity Objects?

I’m struggling with how I should build out my entities, services, and DAOs in an MVC web application when it comes to returning a list (array) of data. On one hand, returning an array of entity ...
3
votes
3answers
239 views

Decoupling and Command Pattern

I am working on some project to learn how to make bigger and better software (multiplayer game) and I found a problem about having in my code a design pattern Command Pattern and anti-pattern God ...
0
votes
0answers
34 views

REST API design: communicating order of inputs is important to the user (in POST request)

Let's say I have a REST endpoint where the order of inputs for a given field is important: POST Request: api.myrestendpoint.com/evolution-timeline/ inputs: {'this_list_should_be_ordered' : [ 'reptiles'...
-2
votes
1answer
87 views

What are the names of the following patterns?

Two different patterns: Acting on a single object by multiple services that can modify it as they wish. So basically we would have some kind of a "chain" that modifies a single object by ...
25
votes
6answers
7k views

Visitor Pattern: what's the point of the `accept` method?

I'm trying to fully understand the visitor pattern. What I've learnt so far (correct me if I'm wrong) is: It's about adding operations to classes, without modifying the source code of those classes. ...
-2
votes
1answer
84 views

Conditional command pattern

I have an abstraction that defines something like a command pattern, interface Participant { void proceed(); } Participants are grouped in a collection and are called all together. But each ...
1
vote
2answers
92 views

Can other behavioral OOP design patterns be expressed in terms of Strategy and Template Method Patterns for behaviour parameterization?

I'm studying OOP design patterns in a solution-oriented way which I mean not concentrating just one pattern but with a comparative analysis like their combined or hybrid usages and equivalents in ...
0
votes
1answer
86 views

Repository layer with multiple data sources

I am implementing a repository layer in my mobile application. I would like the repository layer to complete to abstract the details about where the data it coming from/ or how we retrieve it from the ...
-6
votes
1answer
246 views

State design pattern for vending machine

I have to write a java program for a vending machine which: Accepts coins of 1,5,10,25 Cents i.e. penny, nickel, dime, and quarter. Allow user to select products Coke(25), Pepsi(35), Soda(45) Allow ...
1
vote
3answers
97 views

What design pattern to be used for more duplicate elements

I have to create a class named Phone, which can be any phone like Android, iOS and Windows. Again in Android, I will have various types of phones. For me challenge is, I have to maintain more than 100 ...
0
votes
2answers
115 views

Encoding const-ness on interfaces. Readers - Writers vs Const wrapper

This question is based on this separate question on stack overflow. I have a very low-level structure meant to compactly save presets on flash memory. For simplicity I am going to use stored_record as ...
-4
votes
1answer
58 views

Name of design pattern where type and instance classes are mirrored

I have used this design pattern in several entity-component designs. Now I want to introduce it to my team: It concerns a type-of relationship, where the instance structure and the type structure are ...
0
votes
0answers
58 views

Java Design Practice

I have gone through similar questions on this site and stackoverflow.com, but because I am still curious and want to cover all possible spectrums of this design, I am asking this question. I am ...
2
votes
1answer
38 views

Pattern to combine orders from different systems

We have a legacy order system and a new order system that are both currently active. The legacy order system takes 'offline' orders still, the new order system handles 'online' orders but uses the ...
0
votes
3answers
266 views

Design pattern to validate list of conditions

Background: I have a JSON object (named JSONConditionObject) which looks like the following, { "condition1":"value1", "condition2":"value2,value3 ..." ...
1
vote
1answer
89 views

Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class

I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...
1
vote
1answer
83 views

What are the main aspects to consider in the design of a customised pattern?

(I’m trying to phrase this question to be as specific as it can get, but since I’m mostly interested in high-level design it might be a bit still too vague. Let me know if I need to edit it or specify ...
0
votes
2answers
63 views

User-friendly parameter parsing from yaml

Problem I have designed an evaluation tool (in python) and need some help to make it more user friendly. The tool requires ~100 (nested) parameters, which it gets from a yaml file and stores ...
0
votes
1answer
67 views

What to do with a legacy code base with no unit tests and complex architectural structure [duplicate]

I have been working for my company for almost a year now and been primarily focused on adding features and maintaining two 15+-year-old WPF Projects and one 20+-year-old WinForms Project. The ...
-4
votes
1answer
77 views

What is best design pattern to simplfy class with a lot of options to create it?

I have a base class [for example]: class base { private: std::string name; public: virtual void set_name(const std::string& name) = 0; virtual std::string get_name() const = 0; }; ...
-2
votes
2answers
114 views

Prevent duplicate code in MVC

I have multi endpoint for my website ( Backend, Api, internal api for application and ... ) There is a lot of code that duplicate between this endpoints. for example for signup I repeat these lines 3 ...
0
votes
1answer
113 views

Is it a standard practice to have a single application/controller writing to database

I've been interviewed by some experienced engineer, when he strongly disagreed with some statements I said: Assuming full control over your applications, It's a standard practice to make writes-to-...

1 2
3
4 5
80