Stack Exchange Network

Stack Exchange network consists of 175 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.

10
votes
6answers
2k views

Questioning one of the arguments for dependency injection frameworks: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, you ...
1
vote
3answers
182 views

Different Redis instances for different microservices?

Say that we have Kubernetes running with n pods, each being a separate microservice. Now, some of those services need a caching layer. When we take into consideration: the fact that Redis was tested ...
1
vote
1answer
135 views

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like: login (UserAuthenticateModel) Handle user sessions: user login tokens, fetching user from session if set in session, ect' (UserSessionsModel) ...
1
vote
1answer
137 views

How to design a reassignable global instance that can be referenced by many other classes

I have a DeviceManager class which can handle different physical devices, and to say there are Classes A,B,C, which require a DeviceManager instance as dependency. They should always use the same ...
1
vote
1answer
75 views

Ideas for designing a system for processing status updates [on hold]

Given that this question is related to my work, I will simplify what I need to do. The system consists of 4 primary types of statuses (internally, we call them events): Working, not operating ...
2
votes
1answer
106 views

How to model workflows

I'm building a helpdesk-type system, where there are: Customer - can submit/resubmit tickets; Manager - can review submitted tickets, assign to developers (one ticket to multiple developers), review ...
4
votes
2answers
209 views

Heavy task exposed via a REST API

A part of a system I am currently reviewing, consists of a master node which calls several slave nodes using REST APIs. The slave nodes are scattered throughout the world on different servers, and ...
0
votes
1answer
78 views

What is the name of the pattern where the framework owns your event/state object and you don't keep a pointer to it? [on hold]

There's a pattern sometime used that I'd like to know the name for. It's when you have a domain-specific state object that keeps track of progress through some kind of multi-step process which is run ...
3
votes
2answers
168 views

Ruby: Exceptions for flow control inside an .each block

Consider the following minimal example: class SomeException < StandardError end class Example @@logger = Logger.new @@failure_count = 0 def do_a_thing(array) raise SomeException unless ...
1
vote
2answers
104 views

Observer reporting to multiple layers up from the bottom of hierarchy

There is a swarm of objects. When a new unit of certain kind appears on the frame, the swarm integrates this object by calling some add_new_unit method. Above the swarm is a controller abstraction, ...
0
votes
1answer
45 views

Is it a usecase for a factory pattern when loading configs in a constructor for an API call?

I have a class called GatewayAPI, which has to load configs from a file, when used. I first wanted to put the get_config() method in the constructor, but I don't like this design for testing purposes. ...
7
votes
5answers
457 views

Best Practice - Wrapping if around function call vs Adding early exit if guard in function

I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax. I'm not asking what is the best approach when in a function, I am ...
-1
votes
1answer
60 views

How to build a custom intermediate operation pipeline in Java for a series of API calls? [on hold]

I am working on a project which provides a list of operations to be done on an entity, and each operation is an API call to the backend. Let's say the entity is a file, and operations are convert, ...
11
votes
5answers
8k views

Refactoring constructor that has too many parameters [duplicate]

I'm in my first two months as a software engineer and just wanted to get advice on if this can be improved upon. I've created a class that represents data from RFID in the form of a message: class ...
1
vote
1answer
268 views

Windows Service with authentication, some UI required

I have to build a Windows Service which requires OAuth2 authentication. The service is intended (like all services should be) to run unattended (no user need to be logged in in Windows). The problem ...
-2
votes
0answers
24 views

Extending a data class consumed in various place because one of the consumers requires a new field [closed]

I have a class A that is the return type of a process (let's call it M.getData()) that is consumed by several procedures through the code base (lets call them P1, P2 and P3). This class A is part of a ...
2
votes
2answers
67 views

How to implement change log of a ticket in complaint management system [closed]

One of the requirement, in the complaint management system were are designing, is to implement complete history of the ticket. For example Status was changed (new to pending to work in progres to ...
1
vote
1answer
66 views

Why do some eShopOnContainers Service API Unit Tests not reference API classes only WebMVC? [on hold]

I have been trying to learn more about MicroServices architecture and I am using Microsoft's eShopOnContainers as a reference because I am familiar with .NET. I am getting into the part about testing, ...
2
votes
1answer
42 views

Architecture design for Linux administrative interface

I've developed an IoT device utilising OpenWrt so my design needs run a on a shoe-string budget of resources. I need to be able to push small amounts of data, up to 300bytes to my app on a very ...
4
votes
2answers
230 views

Doesn't repository pattern in clean architecture violate Dependency inversion principle?

From what I have read and seen clean architecture assumes that you have some entities which know nothing about persistence though at the same layer as they reside there might be an interface which has ...
2
votes
3answers
139 views

C# Pattern for Creating/Hiding Object Graph Creation

I'd like to get some advice on what would be a good approach at hiding the creation of an object graph. In the code below I would like SomeClass to not be directly responsible for the creation of the ...
6
votes
2answers
2k views

React: Nested object as state vs individual properties

Are there any use-cases where a nested object as state is either more optimal/easier to work with than individual properties? For instance if I wanted to express some user controls for interacting ...
2
votes
0answers
49 views

How should domain model entities expose information about the current state of their properties?

I'm new to DDD, so please bear with me. I am trying to design a domain model around an extremely large and complex existing system, where most of the current "domain" logic is either in the UI or in ...
1
vote
0answers
38 views

Third-party API wrapper in Java: how to design

Suppose, there's a site that provides an API, such as this: Users post questions, answers on that site You can make GET and POST calls There are two types of authentication: weak (only gives read ...
1
vote
0answers
11 views

different data connectors for different objects and users

I have an application which needs to store different objects in different data stores based on the user's authorization credentials. I.E. the user may need to save object 1 to their BI postgres ...
3
votes
4answers
206 views

How to get a decoupled design without injecting repositories inside entities

I am facing the following situation: I have to develop a system that has to calculate the price of a car so i need to calculate the prices of all the Pieces that make up the car and then total them. ...
0
votes
1answer
130 views

How to connect two objects that communicate with each other?

I am writing a simple chat using Node.js, Websockets and Vue.js. Specifically, I have a Vue instance and a Websockets Client. When a user presses a "Submit" button, Vue asks the Client to send a ...
2
votes
2answers
135 views

Strategy pattern and different implementation

I am still learning Design Patterns and I have a situation in my hand. I am developing a simple employee management Python program. An employee can be a Developer, Senior Developer, Lead Developer, ...
1
vote
2answers
145 views

Unique Identifiers for classes - Java with Spring

My use case requires me to implement multiple validators which implement the interface: public interface Validator { boolean validate(Object o); } Based on the business group of the Object o, a ...
2
votes
2answers
56 views

Swappable state object or decoupling data and functions

I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
0
votes
3answers
84 views

How can I do a step based design form my applicaiton?

I want to create an application that has some optional steps. But I could not decide how to do step plans. It looks like a workflow. I have a Work entity. This work includes specific business steps. ...
5
votes
1answer
109 views

Working with “external” object IDs

I have often encountered a situation in which users of a program (not necessarily human, just an external agent) need to be able to reference objects of a class with a certain "external" identifier, ...
3
votes
2answers
315 views

How to use the MVP pattern in embedded systems?

I am defining the architecture for an embedded system provided with an LCD touch screen for interacting with the user. To describe my problem I can use a washing machine provided with LCD touch screen ...
0
votes
1answer
142 views

Keeping steps in sync of long running process and creating common layer for code repetition

I have 1 long running process wrapped inside a method and it is for 2 different types like below: Type1 Type2 Code: public interface IBaseType { MyResult LongRunningProcess(int jobId,...
0
votes
1answer
68 views

Should there not be methods intended to be only called from inside of the package, but from the outside of the class they're defined in?

Note: This is a follow-up to this question on StackOverflow. I have to write a wrapper in Python to an external API, accessible through HTTP. The code is supposed to be publicly available on GitHub. ...
0
votes
1answer
103 views

How to bring a code to conformance with tell, don't ask without creating tons of methods on other classes?

It used to be fairly common for people to call a getter, do some calculation on it, then call a setter with the result. This is a clear sign your calculation actually belongs to the class you called ...
1
vote
0answers
41 views

How to join two sets of 6 tables and select the list into another set of 6 tables

A1 |__A2 |__A3 |__A4 |__A5 B1 |__B2 |__B3 |__B4 |__B5 C1 |__C2 |__C3 |__C4 |__C5 Given a list of A and a list of B, we want to "join" ...
11
votes
5answers
693 views

Pure functional vs tell, don't ask?

"The ideal number of arguments for a function is zero" is plain wrong. The ideal number of arguments is exactly the number needed to enable your function to be side-effect free. Less than that and you ...
0
votes
3answers
103 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
0
votes
7answers
299 views

Good object oriented practice to use an object to build itself?

Do you think its a good OO practice to use parts of an object to build itself? Here is an example. var car = new Car { Make = BuildMake(), Model = BuildModel(), Vin = ...
2
votes
2answers
7k views

What is the best way to create DTOs from entities and update entities from DTOs in a layered architecture?

Option 1: At first I would make a call to my service layer, which served as an API for my core domain, to get a domain object or a list of domain objects and then pass them into the assembler which ...
0
votes
1answer
48 views

Pipeline design pattern with context for chaining REST API calls

Just like the title says, I want to use the pipeline design pattern for chaining related API calls. The context will store the data that will be used to create a payload. For example, I have the ...
0
votes
3answers
192 views

Responsibility of a Factory

I am trying to refactor a huge chunk of our software, and it requires to set up a factory. However, I am not sure where lies its responsibility. (PS: The code below is shown simply as an illustration ...
3
votes
3answers
88 views

Open Close Principle is applicable when requirement is to add new operation(s) to existing type?

I understand OCP in SOLID can be applied when we have same set of interfaces defined via abstract type, so that we can have varying implementations of those interfaces via concrete types. For example,...
0
votes
2answers
102 views

How to handle command line parameters

I am writing a gui that is supposed to replace a fairly large shellscript in order to make the usage easier for not-so-technical people. The script calls a certain program (saga_cmd) multiple times ...
11
votes
6answers
518 views

DDD meets OOP: How to implement an object-oriented repository?

A typical implementation of a DDD repository doesn't look very OO, for example a save() method: package com.example.domain; public class Product { /* public attributes for brevity */ public ...
3
votes
1answer
183 views

Understanding interface injection

Quoting the definition of interface injection from Wikipedia : The advantage of interface injection is that dependencies can be completely ignorant of their clients yet can still receive a ...
3
votes
3answers
2k views

Decorator design pattern in swift

I'm reading "Head first design patterns" (here you can find exact example mentioned in book) While going through Decorator design pattern, everything was crisp and clear until I stumbled into this ...
1
vote
1answer
111 views

CQRS command that needs to work with multiple aggregate roots

I have have a business process that receives an order request which also includes full customer information. In the cases where the external customer ID from that order request is not found in our DB,...
2
votes
4answers
138 views

What is the name of DB design pattern which support only soft-deletes and soft-updates?

I heard that there is some DB design in relational databases where updating a record will create a new record with different timestamp or status. Also, deletion will be soft-delete (it updates the ...