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
20
votes
7answers
16k views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
3
votes
3answers
99 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 ...
3
votes
1answer
787 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 ...
211
votes
16answers
46k views

My boss asks me to stop writing small functions and do everything in the same loop

I have read a book called Clean Code by Robert C. Martin. In this book I've seen many methods to clean up code like writing small functions, choosing names carefully, etc. It seems by far the most ...
0
votes
0answers
23 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'...
15
votes
2answers
13k views

Why separate class CommandHandler with Handle() instead of handling method in Command itself

I have a part of CQRS pattern implemented using S#arp Architecture like this: public class MyCommand { public CustomerId { get; set; } // some other fields } public class ...
0
votes
1answer
63 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 ...
21
votes
4answers
6k 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. ...
-1
votes
1answer
60 views

How to design a repository when datasource differs based on DML/READ operations?

We are starting our new application in which we using MS SQL DB for all our insert/update/delete/select ie. both SELECT and DML operations. But, soon we will have two different sources. SQL Server ...
4
votes
2answers
407 views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
-2
votes
1answer
71 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 ...
-1
votes
0answers
55 views

What is the name of this (suspected, presumably) design pattern that: converts inline, top-down code into lists of hook functions?

Recently, I've done a great uplift, cleanup of one of my projects – I've switched from inline-snippets of code for sequences of various operations, mostly hooks (post-install-like hooks), like make, ...
-3
votes
1answer
71 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 ...
0
votes
2answers
76 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 ...
24
votes
4answers
8k views

Is Functional Programming a viable alternative to dependency injection patterns?

I have recently been reading a book entitled Functional Programming in C# and it occurs to me that the immutable and stateless nature of functional programming accomplishes similar outcomes to ...
0
votes
2answers
62 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
2answers
69 views

Force State changing of an Object only from Holder

Suppose I have a Button class with a color attribute. I also have a Canvas class which stores all Buttons. Every time a color is being changed, some side action must take place (in this example, for ...
-1
votes
1answer
672 views

Update Entity for Repository Pattern and UOW Pattern C#

In one mock solution, I have created 3 mock projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer. I haven't yet to add ...
-6
votes
1answer
66 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
86 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
113 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 ...
0
votes
2answers
297 views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
1
vote
2answers
299 views

REST API Client Library Design

I'm working on a reusable client library to abstract a REST endpoint that we use in many of our in-house applications. It is actually split into 3 APIs, and certain endpoints/resources require ...
4
votes
3answers
239 views

Working with “external” object identifiers

Note: I wrote this question in a way that made it seem I'm mainly concerned with the memory usage and ways to optimise this. Rather, my original intention (and my current intention, upon revisiting ...
-1
votes
2answers
165 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
-2
votes
0answers
30 views

Is there a way to split the db workload between multiple instances of the same service?

I have a service which on timer needs to look into a db table and go though each item individually and make some requests for it elsewhere. In order to make this service scalable, I need a way to make ...
1
vote
1answer
30 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 ...
-4
votes
1answer
56 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
47 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
2answers
305 views

destroy object once it won't be used anymore in flyweight pattern

I want to use flyweight pattern to return the same instance of my object each time. public class ThingFactory { private static final HashMap<UUID, Thing> things = new HashMap<>(); ...
-2
votes
0answers
28 views

should inversion of control throw duplicate template and terminate process

Inversion of control is reading .xmls files, these files are templates for the container. Input for IOC: Directory path, Then service iterate on all .xml in that directory and register them, each xml ...
0
votes
2answers
74 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 ..." ...
11
votes
5answers
2k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
1
vote
1answer
80 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
79 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 ...
-2
votes
2answers
96 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 ...
2
votes
1answer
132 views

OOP: Interface design when having objects embedded in parent classes

During the design of a small app I ended up with two possible design alternatives that both would work but, somehow, I feel one could be better than the other in terms of following OOP Principles, ...
3
votes
2answers
898 views

Thinking pragmatically about scalability

I was recently asked as an exercise to design a scalable graph. My first intuition was how to seperate the graph and distribute it (sharding,consistent hashing..etc) Turns out my thinking was on ...
-1
votes
1answer
40 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
70 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; }; ...
0
votes
2answers
624 views

Java Design for Data enrichment based on logic defined in a database

I have the following requirement. Read data from a messaging Queue and process each message to enrich the message and then finally send the enriched message to a different system. The enrichment ...
0
votes
1answer
109 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-...
3
votes
1answer
418 views

Is Enum Polymorphism bad for DAO Methods?

I have been going back and forth in a discussion about polymorphic enums to call different DAO methods depending on enum entry, and I haven't been able to get a common agreement on this subject. Lets ...
0
votes
3answers
130 views

OOD vs MVC; Live Objects vs Everything in Database

How to make memory-efficient code, but still have all the possible code nicely encapsulated ? I have a feeling that the OO (object oriented) approach is more intuitive and the code is nicely ...
-1
votes
2answers
97 views

Is there a 3rd party API Pattern?

I'm building a front end that interfaces with a 3rd party API, and my question is regarding the proper pattern to use with that third party API. My existing code isn't very sophisticated, and I find ...
1
vote
1answer
627 views

Architecture for message processing with scheduling, at scale

I have to design the architecture of a system that processes messages in a distributed manner. If this were the only requirement, I would use a message queue like Kafka and distribute the work with ...
4
votes
2answers
175 views

How to design a SOLID pipeline with different inputs

I regularly have the situation that I have some complex logic that I break into steps. For example an import of an Excel file where I need to apply some logic or a complex calculation that I break ...
-1
votes
1answer
47 views

Preventing name collision between user-defined modules within a framework

I'm a contributor to a framework that's designed for producing synthetic data. The system allows the end-user to create custom data generators and load them into the framework. Currently we store the ...
-2
votes
0answers
37 views

How to push data from a n applicaiton to other applications?

I want to create a main WPF (c#) desktop application that sends a json data colleciton to other client applications form internet. The other client applications are wpf desktop as well. The data ...
-5
votes
0answers
25 views

Instantaneous review of conditions

My question may seem rudimentary, but I have not been able to find a good solution to my problem. I get information from an API and process it. My users define warnings that, for example, if a ...

1
2 3 4 5
78