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
1 answer
158 views

How do we nest decorators?

It is possible to nest many decorators. @decorator_one @decorator_two @decorator_three @decorator_four def some_silly_function(): pass How do we write a decorator class so that the order in which ...
178 votes
6 answers
285k views

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
0 votes
1 answer
227 views

Static data reuse

I'm going to describe the situation first and ask questions in the end. I need to validate a scalar value using the Symfony Validator component. The value is an associative array. Now I have defined ...
0 votes
0 answers
41 views

Combining Strategy and Decorator pattern (see GOF) to Spectrogram computation

I'm trying to design and develop a software (part of a bigger application) that should compute and render a spectrogram. The spectrogram can be rendered either from live microphone or a file (assuming ...
159 votes
9 answers
73k views

When is it not appropriate to use the dependency injection pattern?

Since learning (and loving) automated testing I have found myself using the dependency injection pattern in almost every project. Is it always appropriate to use this pattern when working with ...
1 vote
2 answers
767 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, ...
2 votes
3 answers
211 views

Method that returns an object is it adequate for TDD?

Let's suppose I want to follow TDD (Test driven development) and I want to implement a class that is supposed to return a considerable object. It starts to get really complex in my opinion and doesn't ...
1 vote
1 answer
75 views

Composite repositories: minimizing dependency injections

I have an application with dependency injection that consumes a REST API. The API calls are abstracted into entity-specific repositories. Some of the repositories are: HttpNotebookRepository, ...
1 vote
0 answers
72 views

Limiting exposed interface for state transitions

Scenario: Given a class with some internal state and methods to manipulate this state, I want to limit the exposed methods that are available to potential clients/users of my API. TLDR: In the ...
4 votes
1 answer
341 views

Dynamic Object Abilities When Saving State

I have n classes that extends from a State class, the purpose of the State class is to manage the state of the extended classes. For each class we need to save it in the database, remove it and select ...
5 votes
3 answers
1k views

Handling common code among presenters

I'm facing some issues related to code duplication when following MVP architectural pattern in an Android project that I'm working with. My project structure is separated by packages: data, domain, ...
2 votes
1 answer
417 views

Creating an internet gateway for a Bluetooth Low Energy device

I have a device that connects using Bluetooth Low Energy (BLE). I want it to communicate with a server over the internet using a smartphone as a gateway. I have thought of different approaches and I ...
3 votes
2 answers
214 views

Creating an abstraction just for exception handling - a pattern or anti-pattern?

Assume that an external library or framework not under our control exposes a Controller API: abstract class Controller { abstract fun call(): Result } Assume that we want to handle exceptions ...
-1 votes
1 answer
40 views

How to handle dependencies between objects/components

Im currently working on a college project on the simulation of magnetic interactions of particles, see physical simulation: design thoughts. Right now im starting to code my system according to this ...
1 vote
3 answers
170 views

Is in my case role based access better than permissions?

Hello StackExchange community, I'm in a bit of an impasse for my current project. The software in question is a collaborative program designed to let employees work together on the platform and assign ...
-1 votes
1 answer
79 views

How can I prevent an object from being re-sanitized everytime it is passed as input to a function?

Suppose that I have a class named CharStream Additionally, there are a large number of functions which convert their function input into a CharStream def funky_the_function(_input): input = ...
2 votes
2 answers
186 views

Why do we separate interface when implementing interface injection variant of DI?

With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase. public interface ServiceSetter { public void setService(Service service); } Why ...
66 votes
12 answers
34k views

Is this a decent use-case for goto in C?

I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the ...
1 vote
4 answers
1k views

Should an MVP/MVC Model contain behaviour?

I have read plenty of questions on here, which appear to confuse the MVP/MVC Model with the Domain Model. In my mind the MVP Model calls the Service, which then calls a rich Domain Model i.e. the MVC/...
0 votes
2 answers
2k 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 ...
2 votes
2 answers
308 views

Exposing methods for polymorphic children from the aggregate root

Consider the following fictitious toy example: There is an aggregate root DayChecklist that holds a list of Tasks planned for the day: class DayChecklist { String id; DateTime today; ... ...
-2 votes
0 answers
27 views

Design pattern and middleware solution [duplicate]

I am a junior developper using Intersystem Ensemble in my job and i'm wondering how does design pattern relate to that kind of software ? For exemple, i've been given the following task : Check for a ...
2 votes
3 answers
347 views

Design pattern to create a shared lib architecture

I am making a renderer as a hobby, one thing I thought to try is making the low levelAPI be dynamically swappable, i.e. you could have an opengl or vulkan backend and switch between the two without ...
2 votes
2 answers
105 views

Pattern for a base class to do pre-validation and/or post-processing on a deriving class's overridden method?

I have the following pattern repeating itself in multiple places: abstract class Database { void connect() { this.setStatus( CONNECTING ) try { await this.realConnect() } catch ...
-2 votes
0 answers
62 views

Design Pattern for a showroom project

Good morning everyone I am doing my first real software engineering project and have been given the task of determining whether it is possible to use Design Patterns for our project. Context: The team ...
1 vote
1 answer
143 views

Storing multiple instances on a Singleton?

RefactoringGuru's example Singleton in Python has an _instances dictionary field class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls....
1 vote
2 answers
530 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 ...
3 votes
4 answers
1k views

Do I use Repository or Service Object to Perform Logging?

I'm working in Java Spring, and I have typical service and repository layers. The repository grabs a JSON; passes it along to the service; service maps the repository response to a DTO. I also need ...
5 votes
3 answers
673 views

Designing a flexible search API response

Quick Summary I'm building a search micro-service that will allow searching across different types of resources in a particular system (e.g. blog posts, users etc.). The API that will be exposed will ...
1 vote
1 answer
165 views

Specification pattern and maintaining domain logic inside entity

I would like to know more about the Specification Pattern, as it is described in Eric Evan's book "Domain Driven Design". One of the key points Evans makes is that the domain model contains ...
1 vote
1 answer
85 views

Is it an acceptable pattern to put derived classes inside an abstract base class in Java?

Suppose I have some Java code such as the following (in this case, the use of the name "interaction" is referring to interacting with an object in a video game): public abstract class ...
4 votes
4 answers
575 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 ...
2 votes
1 answer
268 views

Is it OK to deprecate methods that need to be public due to the packaging model but are not to be used outside the codebase in Java?

I am currently working on a semi-large project that has several packages. There are 3 main packages, a "client" package, a "server" package and a "common" package. There are two jars, one for the ...
0 votes
0 answers
62 views

REST API design - Categorised response objects - All, Sub, Dub movies paged response

I am having trouble deciding what is the best way to implement a REST API which does the following: When page gets loaded, it displays a list of Movies and above is a category selector tab (ALL, SUB, ...
5 votes
2 answers
1k views

Is returning true or throwing an exception good or bad code practice?

I am focusing on learning better design and wondered if this code is good or an anti-pattern? The function Validate() returns true if the data is correct, else it will throw an exception with a ...
2 votes
2 answers
682 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<>(); ...
36 votes
9 answers
15k views

Why do we need a Builder class when implementing a Builder pattern?

I have seen many implementations of the Builder pattern (mainly in Java). All of them have an entity class (let's say a Person class), and a builder class PersonBuilder. The builder "stacks" a variety ...
157 votes
8 answers
65k views

Criticism and disadvantages of dependency injection

Dependency injection (DI) is a well known and fashionable pattern. Most of engineers know its advantages, like: Making isolation in unit testing possible/easy Explicitly defining dependencies of a ...
5 votes
2 answers
634 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
1 answer
81 views

How to refactor parallel inheritance tree?

I have a (php) program, which must change yearly. This program calculates tax for every year and there are sometime changes in requirements. First, the user fills their incomes, expenses, etc. Then ...
0 votes
1 answer
119 views

Are there any drawbacks to partial application?

Consider the following Typescript code: function exampleAction(target: Target, options: ExampleActionOptions) { // ... } export function getExampleAction(options: ExampleActionOptions) { return (...
0 votes
1 answer
131 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()...
1 vote
4 answers
232 views

Most efficient way to represent a random ordering of the numbers 0-10

I am currently looking for a way to encode a list of random numbers most efficently (as in length). To be specific, I have an array of 11 numbers containing each number from 0 to 10. The order will be ...
7 votes
3 answers
3k views

How to prevent overlap booking on a calendar booking system

As an exercise, I am trying to design a simple calendar booking system for multiple meeting rooms. I kind of got my head around some requirements such as find available rooms for a given time range, ...
3 votes
1 answer
853 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 ...
3 votes
1 answer
180 views

Visitor pattern applicable ? - Applying rules to a list of registrations

I have a list of Registration's, on which I need to apply a set of rules to each individually. Rules can be a single Rule, or a sequence of rules, representable by a tree. One rule is a ...
70 votes
6 answers
71k views

What is a helper? Is it a design pattern? Is it an algorithm?

Maybe a little tongue-in-cheek, but as I can't find this answer anywhere through Google, so to ensure Software Engineering has the answer: What is a helper? I have seen the name being used ...
1 vote
1 answer
311 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 ...
4 votes
1 answer
379 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 ...
3 votes
2 answers
295 views

Is it a good idea to have separate UI components make their own webservice calls?

I have few UI components in an angularjs web-application. Each display data based upon same input. One shows stats which are calculated on the basis of a time period. Other shows a chart of daily ...

1
2 3 4 5
87