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
1answer
107 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
51 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 ...
5
votes
8answers
286 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? ...
21
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
43 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
51 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
136 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
28 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
181 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
66 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, ...
3
votes
0answers
59 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
53 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 ...
0
votes
0answers
41 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
122 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
60 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
300 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 (...
-1
votes
0answers
61 views

Is there a well-known design pattern being followed by GalleryHasMedia?

Here is a class called GalleryHasMedia, which is used within a popular content management framework called Sonata: https://github.com/sonata-project/SonataMediaBundle/blob/3.x/src/Model/...
3
votes
2answers
121 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
119 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
121 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
185 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 ...
21
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 ...
58
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
25 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
87 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
36 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
218 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
128 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 ...
1
vote
1answer
62 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
816 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
27 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
70 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
156 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
168 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
102 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
vote
1answer
37 views

Load for Date dimension table of a warehouse

I have a general question about loading data into a data warehouse (DW). This is basically a followup to an older question of mine. I have a general understanding problem about fill the [Date] ...
3
votes
2answers
112 views

Enterprise application warehousing and relational database

I have a general question about design pattern for an enterprise application. I read a lot about it but its actually hard to find an answer because most you find it rater about how to design a data ...
1
vote
1answer
104 views

Is designing a generic parameterized class with methods of it accepting higher order functions a functional technique that we can use in Java 8?

Recently I have asked this question: How do you rewrite the code which using generics and functionals in Java 8 and mixing oop and functional programming by using only object-oriented? on ...
1
vote
0answers
76 views

Removing duplicate code with multiple APIs

I have multiple APIs doing the same thing but the code is copied for each API. The names of fields and formats of certain fields like dates are different between the various APIs, but everything is ...
1
vote
0answers
62 views

Composing objects: how can I enforce an interface upon each component?

My goal was to be able to create an object which is composed by other objects without having to know beforehand what these objects were, then do checks to see if they actually exist, then add them to ...
0
votes
1answer
56 views

Decorator Pattern - Necessity of an abstract parent vs Default Interface method [closed]

I am trying to understand better the decorator pattern. I have read an article with an example implementation in java and of course, GoF book. Do I always need an abstract parent for the decorator? ...
0
votes
1answer
42 views

Wrapping ReactJS UX component library in another layer of abstraction, pros and cons?

There's AntD library with various UX components. Right now I required to wrap all components which I'm using in another layer, to make an abstraction. For example, if I'm using AntForm component I ...
3
votes
8answers
2k views

What's the benefits to use an abstract factory when using interfaces is already suffice?

I get the idea of the factory pattern, but I feel that it is really not necessary to use this pattern. For example, below is some code I saw (C#) that use factory method: public interface IAnimal { ...
1
vote
2answers
166 views

Simple Snake Game in C++

I posted this question originally in Code Review, but then thought that I could possibly get more feedback about the design here. I just finished writing a simple Snake clone in C++ with the goal of ...
11
votes
4answers
2k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
0
votes
0answers
11 views

Aggregating events [duplicate]

I am in process of designing a service for estimating time of arrivals based on 2 different events. So the service is subscribing to events which in its most simple for looks like: Job (JobId, ...
0
votes
0answers
68 views

How to design for optional dependency / optional functionality

Let's say for a Net Core library that I will deliver to the customer The library define a Interface like IGetData and also a default GetData class. The library also define a ICacher interface with a ...
1
vote
1answer
127 views

Using ThreadLocal in Java

In one of my projects, I have this following use case - I have a variable, that I need to pass around in many methods. Business logic and object creation in those methods are dependent on that ...
0
votes
4answers
122 views

Design pattern for embedding constructor arguments into classes/structs

I am still quite new on here so I hope I am posting in right forum. I am currently writing a small library where I realized I could use some kind of design pattern which lets one pass constructor ...

1 2 3 4 5 75