Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design.

1
vote
0answers
24 views

Functionality design: Multiple sources, multiple consumers with configuration

It is a Design Problem which I am listing out here. I have multiple event sources in my app, each one produces events with the different set of data (but each source is producing only one type of ...
1
vote
2answers
85 views

Avoid mutable field in event handler

I have an event handler that creates objects for which it needs data from both before and after an event. The event handler itself implements Selenium's WebDriverEventListener interface and gets ...
2
votes
3answers
87 views

How to store objects with inconsistant properties

I have real-world materials that are defined by various properties, some common, some not, that I would like to map to objects in C#. For example, Concrete has properties A, B, C, and Metal has ...
0
votes
0answers
33 views

What design patterns should I use for a chatbot? [duplicate]

I am trying to build a chatbot that answers simple queries such as replying to greetings, telling the weather, the time and so on. My plan is to make it a REST API. The client will send queries via ...
1
vote
3answers
146 views

Intent of Command pattern?

In Elements of Reusable Object Oriented software by Erich Gamma, the intent for Command design pattern says: Encapsulate a request as an object, thereby letting you parameterize clients with ...
-2
votes
0answers
33 views

Software architecture of building a set of similar mobile applications at once [on hold]

I would like to build around 500 mobile applications that have same functionality but different design for different 500 clients at once. The applications should be totally different when they ...
9
votes
1answer
152 views

Using friend classes to encapsulate private member functions in C++ - good practice or abuse?

So I noticed it's possible to avoid putting private functions in headers by doing something like this: // In file pred_list.h: class PredicateList { int somePrivateField; ...
2
votes
2answers
74 views

Opposite pattern of Template Method

Do we have pattern, which is opposite to Template Method? I mean, in base class we define parts of algorithm and abstract method which implements algorithm. Then in derived class, in that abstract ...
1
vote
1answer
51 views

How to propagate Setting Class throughout entire project

Here's my setup: Entity Framework Backend Large WPF project that has a main window with 3-4 user controls on it, each of which has 3-4 user controls on it (and so on, in some cases) What I currently ...
5
votes
4answers
184 views

Improved design for a turn-based multiplayer game using AI?

I'm trying to decide which is the best architecture for a turn-based multiplayer game where the players can be either humans or AI and the UI is optional, for instance because the game can just be ...
0
votes
2answers
40 views

Methods taking parameter of Collection should filter the collection themselves or be passed a filtered collection?

Say I have this reasonable contrived situation: public class Toast { public bool Toasted { get; set; } public int MinutesToHeat { get; set;} } public class Toaster ...
2
votes
0answers
25 views

Handling field masks on the statically typed client

Let's say I have a REST API, that has the ability to provide field mask (i.e. the API can return M out of N attributes where M is a subset of N). If a statically typed client (example: one that's ...
0
votes
1answer
49 views

Is it better to initialize semaphores in shared memory or give them as command line arguments? (C++)

I am on a project for which I have to spawn many different processes, all in different executables, and there will be some shared memory segments and some semaphores to synchronize them. I use an "...
-3
votes
0answers
56 views

How to tackle empathy based System Design interview questions? [closed]

There a lot of system design interviews which ask design question which requires a component of empathy. For example, design a recipe app for elderly people taking input of what ingredients are ...
-3
votes
0answers
74 views

Which Design Pattern is most suitable for this problem [duplicate]

The problem states as follows: "A Radio Station broadcasts its programs for listeners through an FM frequency, but in emergency situations the radio channel could be used as an encrypted broadcast" ...
2
votes
3answers
268 views

How correct this little game design without removing its design pattern?

Given is a design of a video game in which a player has several possibilities to adjust his character: Game designers realized it's senseless to be a fire-elemental and water-elemental at the same ...
0
votes
0answers
26 views

WCF service contract for dynamic response based on input request. C# [closed]

Below is a sample format of response and equivalent service contract of my web service looks like. <Players> <Player> <Name>Sachin</Name> <Sport>Cricket</...
1
vote
1answer
69 views

“State” pattern and encapsulation

Suppose we have the following classes: As you see, it's an implementation of the State Pattern. Basically, the Order class proxies the pay() and cancel() method calls to it's concrete OrderState ...
1
vote
1answer
121 views

Java Class Design

I need to send a json response. I use the jackson library to convert the class to json. I have a core java class to which I need to add some more fields to create my json response. I came with two ...
4
votes
2answers
218 views

Injecting a dependency that is a tree of dependencies

Is it a pattern or antipattern to inject a dependency that is a tree of dependencies? For example: public class ClassExample { private IContainer _container; public ClassExample(IContainer ...
2
votes
0answers
42 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
vote
2answers
174 views

Clean architecture, CQRS, and authentication?

I'm working on implementing my first clean architecture and CQRS application, I've stumbled across a bit of logic that's leaving me a bit stumped. I'm working on integrating authorization and ...
2
votes
5answers
335 views

Software design pattern for class method that only should be called once

Say I have a TypeScript class: export class TypeCreator { entities: Set<Whatever> registerEntities(e: Set<Whatever>): Set<Whatever>{ return this.entities = e; } } if ...
0
votes
1answer
79 views

Mediator pattern across web API

What are your thoughts on mediator pattern being used from a client and across a web api?, this means: Command definitions are shared between the client and api. Web api exposes only one ...
2
votes
3answers
96 views

How to calculate overall progress in independent phases?

When using a call-back to show progress on a multi-phase task, I don't know how to calculate the progress per phase well. One of the phases is collecting data, which differs in size from run to run. ...
1
vote
2answers
108 views

Dependency injection in a loop?

Suppose I have a loop (in Python syntax): xml = "<x>...</x>" for i in arr: j = f(x) # some complex computation obj = Class(i, j) xml = obj.run(xml) Does it make sense to use ...
2
votes
0answers
64 views

Python3: How to change the design of a class hierarchy to improve access to objects there buried?

I asked this question already at stackoverflow together with a serialization related part and at codereview for the design part only. Since the design related part receives no answers or comments on ...
1
vote
1answer
64 views

Where and how to handle user password hashing in Clean Architecture?

I'm currently building a new application and trying to apply some of the principles of Clean Architecture. One of my first roadblocks is implementing my own Identity system (to avoid being tightly ...
3
votes
1answer
78 views

If your company ships multiple products, does it make sense to use a mono repo for your integration tests?

Assumption: Each product codebase is in a separate repo. If the product codebase was a mono repo, it would be a no brainer to just put them together. Assumption: Integration tests in this context ...
2
votes
2answers
83 views

A good way to represent an object with multiple interconnected states?

I want to program a simple budget application. In my application, the budget is divided into budget periods (months by default, but it can be bi-weekly or weekly periods). In each period there is a ...
0
votes
7answers
398 views

Is it a good practice to use self-defined exception?

Our team has different opinions about the practice of using self-defined exception for handling the business logic. Someone says it is good as the exception comes meaningful and readable, and the ...
2
votes
1answer
133 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
8
votes
2answers
146 views

fall-through switch for executing a sequence of steps

My program needs to execute a sequence of steps from start to end. But based on different input the start point will vary, e.g, some will run from the first step to end, some will run from the 2nd ...
0
votes
1answer
94 views

Decorator or Facade

I face an issue if to use a decorator or facade pattern to accomplish my needs. Imagine a client wants to play a video. He can use the interface public interface IVideoPlayer { // Prepares ...
1
vote
3answers
113 views

subclass with no logic of abstract class

I have a class named Change which should be abstract and have some basic methods. I have classes Insert, Update and Delete that extends Change. In the case of Insert, Update I just use extend and add ...
-3
votes
1answer
26 views

What is an integration test pattern for an extensible permutation of cases (e.g. dimensions of seed data and filtering by said dimensions)?

Suppose we have a service that returns users in certain categories, e.g. Listens to a certain artist. Listens to a certain playlist. Listens to a certain genre. Is between ages X and Y. Is located in ...
-1
votes
1answer
188 views

Wrong use of factories in Java libraries? [closed]

Some of the Java libraries I have used so far seem to have a Factory for seemingly every other class in the library. Apache's FTP Server project, for example, provides a UserManagerFactory class which ...
2
votes
1answer
144 views

Unit Testability of Builder pattern

I'm looking at the builder pattern for helping setting up dependencies and parameters that may require complex logic for a class. But from the examples I've seen, the builder pattern does not seem ...
2
votes
1answer
81 views

Is there a name for a “multi-instance singleton pattern” — returning a reference for a same-valued object?

I am tasked to write an assembler in C, which lends itself sufficiently well in certain design-pattern scenarios, and in a parsing phase, after tokenization, I need to "fill-in" certain information ...
1
vote
1answer
57 views

Design pattern for common properties: static properties or a separate single instance class?

I need to create properties that have values common to instances of a class. I'm unsure how to solve this problem, so I could use some help. (This is in C#, but isn't a language-specific question.) I'...
1
vote
1answer
49 views

Logging patterns from within library code

I am looking for a design pattern for logging from within library code. Suppose I have a function in a library file that i expect will be used by multiple front-ends (lets assume a CLI and a web): ...
0
votes
2answers
63 views

Singleton's applicability clarification

According to the GOF Design patterns' book, singleton pattern should be used when: there must be exactly one instance of a class, and it must be accessible to clients from a well-known access ...
2
votes
5answers
185 views

Design pattern for creating object hidden from client

I am having difficulty understanding which design pattern would be best for the following scenario. An application uses a database. That database can either be the production version (SQL) or a test ...
2
votes
2answers
116 views

Using injection for services that contain only pure functions

Imagine we have a service like the this: class SomeService { // A random pure function that transforms the input // without doing any remote calls or any side effects function ...
2
votes
1answer
154 views

What are the pros and cons of keeping most of an application's state in a single struct?

In my application, I have a few classes. Many of these classes share common state like a reference to the logger for example. For example, both A and B require some common state to get their job done. ...
0
votes
3answers
84 views

Dependency Injection via Constructors vs Abstract Classes

For the past few days I've been researching the relationship of abstract classes and dependency-injected via the constructor classes. It appears that any time that I can have a dependency-injected ...
-1
votes
1answer
52 views

Design Patterns for an expression project

I have the implemented a calculator that is very similar to the following UML diagram. The only new thing is a new class, a Recognizer class, that says if the expression is written correctly or not. ...
1
vote
0answers
25 views

avoid passing dbsession object to multiple modules

I have a project which has a service-oriented architecture. for example, anything relates to payment is inside payment module. -dao -config -constatnts -middlewares -modules -payment -user -...
0
votes
0answers
95 views

Software Architecture with C# and WPF

We have the need to develop an offline desktop application for a measurement equipment. While having quite a bit of experience in C++, We are new to WPF and VS in general. This software will have a ...
1
vote
1answer
64 views

Managing heterogeneous data

The underlying problem is one I seem to run into a lot. You have a collection of objects with some things in common, but other information about the objects may apply to some of them but not to others....