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.

0
votes
1answer
53 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 "...
2
votes
3answers
278 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 ...
1
vote
1answer
76 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
123 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
230 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
52 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
308 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
359 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
104 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
99 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
117 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
71 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
74 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
81 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
87 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
430 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
143 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
154 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
101 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
114 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
29 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
194 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
148 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
63 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
55 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
68 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
204 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 ...
3
votes
2answers
124 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
162 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
92 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 -...
1
vote
1answer
90 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....
2
votes
3answers
290 views

What are the differences between Threadpool and Object Pool patterns?

I was going through the ThreadPool pattern and it resembled the Object Pool pattern. The only difference that I can think of is that most explanation about the ThreadPool explicitly mentioned the use ...
3
votes
3answers
287 views

When to use xxxResult return value pattern?

I have one method which need to return multiple values whether it was successful or not, what the key used to call the api and if successful the return result. Here is more concrete method, public ...
0
votes
1answer
204 views

DDD - Factory or Service?

I'm new to DDD, and I'm confused at the very start of my DDD project. To setup a context, I'm building the user management part of my app, so I'm building my Account entity, which contains an Id, a ...
1
vote
1answer
144 views

Where and how to connect to external API in my service class?

In my service class I would like to connect to external API. Where and how should I do it? 1) Inject in constructor ExternalClass and assign to private property. Next in other property in constructor ...
1
vote
3answers
154 views

Modelling recurring events

I am in the process of writing a web app to track expenses and which will be multiuser. Everything is fine with a single expense, but I am struggling to find the best way to represent recurring ...
1
vote
2answers
168 views

Dealing with ever-growing domain models

May I be so bold as to ask (from an amateurish point of view), what is the general strategy for dealing with potentially ever expanding domain models? By way of example, I have Staff, and in the ...
3
votes
1answer
111 views

Java inheritance error handling scenario

I looked multiple places for some advice on how to solve this before asking this question, but I couldn't find something similar to this. So I have the following scenario in Java Spring Integration ...
3
votes
2answers
302 views

C++ Gof Design Patterns heavily depends on new or shared_ptr

I'm trying to learn the best practices for code design and reuse in C++ so I am going through the well known GoF Design Patterns Elements of Reusable Object-Oriented Software. I noticed that nearly ...
2
votes
4answers
202 views

Inheritance: When only some concrete objects need to share state

I have a series of classes that represent widgets in a layout system. The base class for all of these concrete widget types is Widget. If I have a Button and a Text Box, these both derive from Widget. ...
1
vote
0answers
42 views

decouple business logic from supporting logic

To prevent business-logic functions from being bloated with supporting-logic* of shared concerns (e.g. authentication, authorization, logging, profiling, ingress rate-limiting) many backend frameworks ...
1
vote
3answers
287 views

Single database query with in-code iteration vs Multiple database queries

Say there is a single database table containing information about two different types of animals: land animals and sea animals. I want to create two lists of animals, one list for each type of animal....
-2
votes
1answer
73 views

Delegation pattern in Python: is it unpopular? Is it considered not Pythonic?

As a Ruby/Rails person, I often deal with method delegation. It's often convenient to delegate a method to a composed object or a constant. Ruby even has a def_delegator helper method to easily build ...
1
vote
2answers
50 views

Thin Controller: Make a Controller Service wrap other Services?

Say you have a HomepageController that' suppose to show all the blogs, users, gallery, and some members-only info (for logged-in users) Normally, it looks like this: <?php class ...
6
votes
3answers
684 views

Can the Flyweight Pattern be used with mutable objects or not?

I recently learned about Flyweight Pattern from this link. It is written there: It’s very important that the flyweight objects are immutable: any operation on the state must be performed by the ...
1
vote
1answer
48 views

Adding Security Layer for multiple services

My web application at the moment accepts REST requests and handled via some controllers, which calls corresponding services to perform the logic. Now I want to add in some security logic before ...
0
votes
1answer
116 views

What does related or dependent mean here?

In Elements of Reusable Object Oriented software by Erich Gamma and friends, the intent for Abstract Factory Pattern says: Provide an interface for creating families of related or dependent objects ...