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
1
vote
0answers
64 views

Best way to check if a value meets a condition and then perform additional logic based on the condition it meets?

I'm curious if there is a pattern or at least a better way to code this situation. For example, say you're writing a rest api for a reporting workflow. You have a User class and a Job class. Each User ...
0
votes
6answers
130 views

Adding client specific method to a listener interface is a good idea?

I'm using a listener pattern where a class A listens for events from various classes B, C, D with the help of a listener interface I Essentially the structure looks like: interface I { void ...
0
votes
1answer
122 views

Name of this enum-based design pattern to get the type

I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface ...
0
votes
3answers
185 views

A case when you can't make processing idempotent

I have just been confirmed for an interview and one of the hint questions given by the recruiter was: "Explain Idempotency and a case when you can't make processing idempotent" I understand ...
1
vote
1answer
50 views

Is this form generator a valid Composite GoF?

Searching for a good PHP real world example, I've found this example of "composite" using: FormElement as Component Fieldset and Form as Containers Input as Leaf (this is my UML from the code): ...
2
votes
1answer
111 views

Is this a valid GoF Adapter example?

After visit dozens of pages searching a "non-sockets-or-iphone-conceptual-example" of Adapter Pattern, I have found this one: Lloyds bank is an international bank offers services worldwide. For ...
3
votes
1answer
125 views

Is there a simpler approach than abstract factories for handling similar, but branching, logic?

I have a medium-sized Angular-based web application that I'm currently implementing some permission components for. Overall, the areas where the permissions components will be used are virtually ...
2
votes
1answer
100 views

State Machine: what object is responsible for state transfer?

I would like to create a state machine. Each State would have its run method, and, according to some logic would then set a next state. Option 1: If each state is responsible for determining a next ...
1
vote
1answer
102 views

Is the Repository pattern a part of the Ports and Adapters concept

Reading the blue book at page 152, we can find this: [A repository] provide methods to add and remove objects, which will encapsulate the actual insertion or removal of data in the data store. ...
10
votes
6answers
2k views

Strategy vs Factory design pattern

I am new to design patterns and working my way through the Factory Method and Strategy patterns. I understand that Factory is a creational pattern and Strategy is behavioral but I struggle to ...
0
votes
2answers
102 views

Design pattern for executing and reverting the tasks in same order

I have a Task in my project , to complete that i have call(REST) multiple external systems. If my call fails at some level , i have to rollback all my previous calls(making call with undo action) . ...
0
votes
2answers
231 views

SimpleFactory vs Factory Method

Let's assume a SimpleFactory that creates a group of objects: public SimpleFactory { public Bycicle createBycicle(String type) { if(type.equals("ONE")) return new OneWheelBycicle(); if(...
0
votes
0answers
35 views

Better way to structure several different API calls with rollbacks?

Currently I'm working on creating something with the following general structure. I want to call 4 different APIs in sequential order (the results of one are needed for the next one). If one throws an ...
1
vote
0answers
38 views

How can I decouple my wrapper API from its underlying SOAP implementation?

In our current architecture, a user has multiple ways they can change an address (as an example). They can do it through an online portal, through our core processor directly, or via a number of apps ...
1
vote
1answer
148 views

Can Value Objects create their own value?

Let's say you have a username value object which has formatting rules e.g., class Username { private $username; public function __construct(string $username) { // thrown an ...
1
vote
1answer
132 views

Should I use an `else lif` or an `if` for the second of two consecutive assertions?

Here's an example of my question in python. Notice there's only a very subtle difference: changing an if to an elif. There's no difference in behavior; if the first if statement is executed, the ...
0
votes
1answer
62 views

Structuring code to support console output and WPF views

Premise: This is for learning purpose. I'm trying to adapt my Console Application code to be served through a WPF Application GUI that I would like to create. One problem is struggling me. Actually ...
7
votes
8answers
401 views

Should a function throw exceptions based on its expected behavior or its goal state?

My coworker and I are debating the correct design for an API. Say we have a function void deleteBlogPost(int postId). What should this function do if the blog post indexed with postId does not exist? ...
24
votes
6answers
5k views

Coupling: Theory vs Reality

Coupling is defined as the knowledge one object has about another one, which describes how dependent they are. The more dependent, the worse, since changes in one would impact in the second. High ...
-3
votes
1answer
47 views

Different input param for the same logic flow

I'm trying to find the best design approach to handle a design change in a new project I'm working on. At the moment, the flow runs and makes some calculations based on a parameter which is used. ...
3
votes
1answer
59 views

Managing multi-server monthly transaction aggregations

Context: A system tracks some sort of transactions (e.g. money flow) for it's whole user base. At the end of the month each entity capable of receiving transactions has to be sent exactly one bill ...
2
votes
2answers
166 views

Builder Pattern: Is it acceptable to use “passing-by-reference” on Director methods?

For teaching purposes, I am trying to create a PHP implementation of a conceptual example of Builder Pattern: First of all, some products: class Product1 { private string $attribute1; ...
0
votes
0answers
29 views

What to Use In Abstract Factory Producer to Choose Concrete Factory? [duplicate]

So to create a concrete factory that extends from an abstract factory class, I usually create a 'producer' class to determine what abstract factory to use. For example: public abstract class ...
3
votes
3answers
202 views

How to use strategy pattern more effectively?

The problem is the following: I have to download a set of JSON files and convert them to a certain format. There are 5 output formats (Let's call them A, B, C, D, E) and all of the downloaded json ...
1
vote
1answer
74 views

Can this simple Bank example be considered as a valid Abstract Factory?

For teaching purposes, I'm trying to replicate in a more faithful way from this conceptual UML (from wikipedia): In a "so-so" real world example, in my case, families of Loans and Insurances: So, ...
4
votes
0answers
95 views

Global variables and common block management in Fortran

Background The high level overview of my situation is described here. I am breaking it apart into smaller, specific questions, such as this one, regarding extensive use of global variables in a ...
0
votes
0answers
65 views

Architecture Design of Command&Control application center for displays

I am facing dilemma on how to best design the following functionality. What design patterns and OOD principles should I use. For simplicity sake following are basic requirements: displays type ...
1
vote
0answers
48 views

How could I reuse common JS modules between several projects?

At my company, we are developing pretty simple React Native and sometimes mobile-only React apps. Most of them have some similar logic, such as 'sign-in by phone' flow, some payments stuff, etc., and ...
3
votes
1answer
196 views

How to modernize large legacy Fortran program? [duplicate]

Problem Background Recently, I joined a government agency as a software engineer/scientist/analyst. Previously, worked in software industry - gained 3 years of software engineering experience at ...
1
vote
2answers
65 views

When using data and domain models, where should validation take place? And how should errors be fed back to the user?

When using data and domain models, where does validation take place? Both or just For example: class UsersDB(): def create(self, user_data): # Create user here return ...
4
votes
4answers
356 views

Do we really need interface classes for the dependency inversion principle?

As a practical example, imagine a Gripper class which represents a robotic gripper in a simulation. Gripper has a TryGrip method, which checks if there's a GrippableItem in the correct position (...
3
votes
2answers
184 views

Abstract Factory: Can Client Class have an aggregation with the Factory?

After searching for some Abstract Factory examples using modern programming languages, I have some dillemas about the sensu lato of conceptual UML schema of Abstract, more specificly about the Client (...
0
votes
2answers
172 views

How to write the following snippet in more cleaner way?

When the caller gives me a call, I need to evaluate n number of criteria which currently I'm doing like if (a & b & c & d & e) Day by day the conditions are growing and it'...
1
vote
1answer
223 views

What is the difference between simple factory and factory method?

I am a little bit confused about simple factory and factory method. My main difficult is the abrut difference between the examples code on the internet, even on wikipedia, where have lots of them, ...
1
vote
1answer
192 views

Program Structure

I'm looking for general advice regarding the structure of applications. In applications I've been building recently, I've started to use a class (I'll refer to it as DataManager for the rest of the ...
22
votes
4answers
4k views

Constructing an object: should I expose or hide parameters passed to the constructor?

I've a habit I just mechanically do without even thinking too much about it. Whenever a constructor is waiting for some parameters, I consider this a public information that should be available by ...
59
votes
8answers
9k views

How do I ensure that interface implementations are implemented in the manner I expected?

Let's say there is a member SomeMethod in an interface ISomeInterface as follows: public interface ISomeInterface { int SomeMethod(string a); } For the purposes of my program, all consumers of ...
0
votes
0answers
29 views

Should redux store take care for fetching, updating and deleting data from an API?

I'm not very familiar with redux, but most of the resources about the topic recommends to place CRUD API calls in the redux store via middlewares and use additional states like: FETCH_SUCCEEDED, ...
3
votes
1answer
155 views

Does it make sense to apply interface segregation to a facade?

In my project, we have a couple different back-end APIs/endpoints that are called by the same front-end page at different times. All of these endpoints are sort of related to the overall "theme" or "...
1
vote
0answers
43 views

How does a framework manager, broker or coordinator class handle pluggable extensions and make them run?

I'm trying to understand if there is a manager/broker/coordinator class in frameworks and I hope so, but what possible ways are in a framework to make it run the pluggable extensions and what the term ...
5
votes
2answers
253 views

Is it good design to have one constructor that supplies a “default” concrete class to another that takes an abstraction?

I like to invert dependencies whenever possible by depending mostly on abstraction and allowing the concrete implementations to be passed into the object by clients, or a factory. I've found this to ...
1
vote
0answers
31 views

How to develop an Import/Export Functionality for my node application

I have a configuration application in Nodejs. It has a Component with name and uuid. A Component can have many Schemas. A Schema has a uuid, name, componentId, json. A Schema can have many ...
3
votes
1answer
142 views

Factory/Strategy Pattern for objects that require different pieces of data

I'm facing some difficulty with designing a factory and/or strategy pattern for building out EmailTemplates. IMO this seems like the design pattern to go with, but I feel like the path I'm going down ...
0
votes
1answer
74 views

Design Patterns for Passing Large Quantity of Parameters in Machine Learning

I am looking to better understand best practices for handling large quantity of parameters. I am particularly interested in the types of parameters involved in machine learning code bases and ...
8
votes
3answers
987 views

An older, experienced contractor used an SQLite DB for various queues - am I, a young dev, justified with feeling uncomfortable with it? [closed]

Context: I'm an embedded dev with only 2 years of solid experience. I'm the sole technical employee of a startup of 4 people. We have an MVP of our product out and are getting ready to develop the ...
1
vote
1answer
28 views

Pattern for schema split across sources

I was not sure how to title this question, but bear with me. My company is building a new product and for it we will use a third-party service (let's call it ENB for short) to be responsible for many ...
0
votes
2answers
121 views

Moving single tenant application with queue to multi tenants web application

I need to move a single-tenant web application to a multi-tenant (about 100 tenants) web application. Tenants are going to share the same application but each tenant is going to have its own database (...
2
votes
1answer
157 views

Correct approach to DDD?

I'm wondering if I'm using the correct architecture in my application. After calling an endpoint in my API, I'm currently going through the following flow: Api.EmployeeController.Update(Api....
2
votes
2answers
257 views

C# - Correct way to convey Null Object design pattern via an interface for client/service?

I've just learnt about the Null Object design pattern, which recommends that the service either return a default null object or throw an null related exception itself so that the client need not worry ...
0
votes
2answers
104 views

Refactor the method which has the sequence of the similarly looking blocks of code to (or towards) the design pattern(s)

I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...

1 2 3
4
5
78