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
2
votes
1answer
89 views

Python: Return or update object

Firstly I am new to Software Engineering and my last question was closed. I am doing my best to ask relevant questions and improve. If you are going to down vote my question I'd really appreciate if ...
2
votes
1answer
100 views

Is it allowed to include the composition in the compositor in the Strategy Pattern

I have a range of different animals in my zoo such as turtles, birds etc. As they all share a common trait such as either swimming, flying etc., I thought a strategy pattern would be appropriate to ...
0
votes
6answers
245 views

Dynamically knowing all the subclasses of a superclass

Say I have a class to model my customers class Customer { public static customerType = 'customer'; } And a subclass class CorporateCustomer extends Customer to model my corporate customers. ...
1
vote
3answers
65 views

How can the relationship of these objects be modelled, so that when given a set of objects I can determine what other objects are compatible?

Consider the follow entities: Bob, Sally, Apples, Oranges, SupermarketA, SupermarketB. The relationship between this is as follows: Bob can buy Apples from SupermarketA and SupermarketB Bob can buy ...
1
vote
1answer
69 views

Doing data manipulation on server side vs client side

Im building a project that stores time series data on a per user basis. On the dashboard of the user it'll show some simple statistical analysis like averages but more importantly, it'll create charts ...
0
votes
0answers
19 views

How to scale raft state to dozens of followers?

I'm looking into developing a distributed pubsub with p2p messaging akin to ROS where instead of being brokered, messages are transported directly from producer to consumer. XY problem - each node ...
1
vote
1answer
40 views

aggregate data for complex API call without coupling modules to parameter object

I am working with an API that is used for registering bookings in a ticket system. Some of the calls I have to make take complex XML objects as arguments. Some data points in these objects have to be ...
0
votes
1answer
46 views

Creating a internet gateway for bluetooth low energy device

I have a device that connect using Bluetooth Low Energy. I would like it to be able to communicate with a server over internet using a smartphone as a gateway. As I approach this I am coming up with ...
-3
votes
1answer
171 views

What are the best practices for writing a long, multi-step process? [closed]

When writing a long process, i.e. one filled with many steps of business logic, what are the best practices for organising it? There are a few different options here that I can see: Just write a long ...
-2
votes
1answer
51 views

Adding unstructured data to a relational database (PostgreSQL)

I'm building a project and I only know the MERN stack. Everywhere I see the general consensus is that Mongo is not good and should only be used in very specific use cases. More importantly, I also ...
2
votes
1answer
40 views

State Pattern: duplication in State and Context

Wikipedia gave an example of State Pattern: Define LowerCaseState and MultipleUpperCaseState, both inherite from State. interface State { void writeName(StateContext context, String name); } ...
3
votes
7answers
316 views

Problem with runaway number of properties

Rewritten Question I appreciate the feedback and in response to that I'm re-writing my question. I can't give my specific situation (classes, etc), nor do I think that it would be helpful, as I work ...
1
vote
1answer
44 views

Should the View pass data inserted from user to Controller or should the Controller get data from View's fields? (MVC Pattern)

My View has a textfield and a button. According to MVC pattern on button click should be called a function of the controller. This function should do some operation on the View's textfield content. It ...
0
votes
0answers
257 views

DRY(Don't repeat yourself) Principle and BFFs (Backend-for-Frontend)

We are about to plan our server architecture and we want to use the BFF strategy with node.js servers to serve multiple front-end apps. However we also want to be able to scale easily (e.g. a new ...
-2
votes
1answer
90 views

What design pattern am I up to here?

I am making a small "search engine app". The app should get three pieces of input from the user: The name of the search engine as a string (e.g. "googe", "duckduckgo", etc) The search term The name ...
-3
votes
1answer
52 views

What patterns exist out there for a job scheduler?

I want to design a system that performs certain actions at a predefined time in the future. i.e. at 2pm on April 10th 2020, do X I'm looking for patterns that would ensure that the intended action ...
0
votes
1answer
90 views

What should the response of the Service Layer be?

My controller calls the service layer. The service layer calls a repository or does whatever it does. If I just return a person object for example how do I know it was successfully retreived? I can ...
0
votes
0answers
32 views

Is it idiomatic to use protobufs as containers within a service?

I love gRPC, but I find every step of the protobuf process rather frustrating (particularly in Python). Even though they are structurally similar to data structures composed of lists and dicts, you ...
-1
votes
1answer
50 views

Exposing java service as static method or seam dependency

Our legacy application provide a static method public static boolean persist(Data data) for service/class callers for data persistence. I do see unit testing issue for callers. Is this also an ...
4
votes
1answer
197 views

Repeating a state in a state machine

I have a state machine in which I might have to restart something when needed (Say restart a hardware). But after restarting, I need to run some tests on the thing. If the tests fail, I need to stop ...
1
vote
3answers
80 views

Design Pattern when base class supports new method overload

The base class (in the base lib, not owned by me), has upgraded its code and add a new method to support additional use cases. This is the existing method signature in the base class: public void ...
2
votes
1answer
75 views

How to simplify a complex factory pattern?

I have a function which takes the incoming request, parses the data and performs an action and posts the results to a webhook. This is running as background as a Celery Task. This function is a common ...
1
vote
1answer
45 views

Validation framework and immutability

I have designed a simple objects validation framework in Java in the context of a code refactoring. The framework has a ValidationRule interface with one method Errors validate(MyObject myObject, ...
1
vote
1answer
37 views

How to implement a chain of events on a tree's CRUD operations?

I am working on a project in which I have a tree with 4 layers and the hierarchy is like this. Customer -> Site -> Location -> Guardroom In DB each entity has its own table and the child knows its ...
2
votes
2answers
36 views

Microkernel architecture for insurance

Working in insurance usually mean you need to deal with a myriad of rules and logic for rating, policy, and claims processing. These are steps in the insurance lifecycle. Every insurance product (...
0
votes
0answers
31 views

Inheritance and instance-storage design suggestions in Django system

I am learning Django and to make the most out of the educational process I am thinking of this hypothetical system and tries to figure out how I would design and implement it. The hypothetical system ...
1
vote
0answers
73 views

Single page dashboard architecture

I am implementing a dashboard. I figured I'd make it work like a SPA for cleaner flow and better performance. When you click a sidebar link, the page/section gets loaded with AJAX. You can still ...
29
votes
7answers
9k views

Polymorphism case study - Design pattern for morphing?

Imagine two classes: class Person { MarriedPerson marry(Person other) {...} } class MarriedPerson extends Person { } The idea is that a Person is automatically "morphed" to type MarriedPerson ...
3
votes
3answers
457 views

Design pattern: How to inject dependencies into a Command pattern

I am pretty new to programming languages and only have limited knowledge about design patterns, so I hope you can help me with the following problem: I have an application that operates on a group of ...
2
votes
1answer
125 views

How to structure OOP multiple calculations?

I am working currently on a project that requires a series (almost 86) calculations to run based on a user data input. The problem is that each calculation has a series of requirements: Should be ...
0
votes
2answers
98 views

Should I refactor this class to use a Factory?

Given the following class in a Legacy code base without any UT's. So any refactoring done should be done on the smallest possible scale, just in order to be able to write UT's. public class Person { ...
3
votes
1answer
50 views

Need technical advice about passing data through UINavigationController

First of all a small introduction, im relatively new to Swift and to programming in general, been doing it for the last year and loving every and each new thing of this vast world. My post is about ...
5
votes
2answers
152 views

DDD Domain Modeling of Transportation Module

I am in the process of trying to model a transportation module for an ERP type system using C# and EF Core. This service is responsible for managing customer pickups and company-owned truck ...
0
votes
1answer
53 views

Should a 3rd party user input validation library be wrapped?

Edit -- I have no limited my question down to a more specific question. Is there an argument not to wrap a 3rd party user input validation library? To me there are a few strong arguments to do so. ...
0
votes
0answers
26 views

Implementing Proxy pattern via concrete inheritance

Say I have some code which consumes a class called Subject, which implements ISubject. Would there be any concerns if I were to build a ProxySubject, which inherits Subject? I like this style because ...
3
votes
1answer
232 views

I often create class cycles by using the Observer Pattern. How can I avoid this?

I often find myself creating class cycles by using the observer pattern. Consider the following scenario: I have a central accessible global data source (Subject) The data source is reflected by many ...
-4
votes
3answers
158 views

How to Replace Many if Statements for many types

I have many dependent statements. What is the best approach to handle these cases dynamically? Example enum UserType { case buyer case seller } enum ViewType { case active case ...
4
votes
4answers
444 views

What kind of logic can Domain Objects realistically contain?

I have been struggling with this concept in the context of web applications ever since I first read about it. The theory states that the domain objects should encapsulate their behaviour and business ...
1
vote
1answer
96 views

How should I construct a complex object having many dependencies?

Consider the construction of the FixAcceptor type below. The code snippet is part of a unit test. var logSource = LogSource.OnMessage | LogSource.Event; var stateStore = new StateStore(); var ...
0
votes
4answers
212 views

Design pattern for a function class

I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions: https://...
0
votes
1answer
60 views

Transitive matching in streaming application

Problem A streaming application should perform matching transitively i.e. if A == B & B == C then A == C Current Implementation Application accepts domain objects in a streaming fashion and ...
-1
votes
1answer
99 views

Is there a name for this pattern of composing a type safe return type from different levels of nested related entities?

I have a problem in my app where I have many entities that can all reference each other in different ways. For example, I have a Job (e.g. build house) that I might assign to a team called "Plumbers" ...
1
vote
2answers
135 views

Chat part of application - using UDP or TCP?

I'm trying to build a section of my app where two users can message each other. I've read about TCP and UDP and it seems like TCP is more suited due to ordered packet delivery. However, TCP requires a ...
0
votes
1answer
79 views

Mapping bidirectional 'toMany' relation from DTO to entity

The application that I am working on has numerous ...toMany relations, e.i. class Model can have several parameters. In Unidirectional world, it is simple to manage a collection. I can clean the ...
1
vote
1answer
77 views

Choosing a suitable design structural pattern for a use case

I have the following models. First, there is a Vector which has a circular DNA sequence. Second, there is a LinearizedVector which could one of below classes. LinearizedVectorBase: ...
1
vote
1answer
52 views

Html development with partial views

Is it a standard practice to develop a HTML project using partial views. Consider a project where the design team will develop the HTMLs based on the requirement & then the backend team will work ...
0
votes
1answer
90 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
1
vote
1answer
56 views

Building a form based on json object?

I'm currently refactoring an older legacy application and use React to rebuild some of the former functionality. This application has a form which has +10 different input fields. The aim is to kind of ...
2
votes
1answer
129 views

Should I use Factory Method design pattern for this problem?

I'm working on an application which needs to open a database file. There are 2 "versions" of this database: one of them is more general data storage, and the other contains "less" information. That ...
1
vote
0answers
66 views

Dao pattern Java and Hibernate

I am trying to create a good pattern for my application. I want to reduce as much as possible the duplicate code and I want to use generics as much as possible. I have created a pattern for this but I ...

1 2
3
4 5
78