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
votes
0answers
65 views

How to use Dependency Injection on repositories in Generic Repository Pattern with base class inheritance

How to dependency inject repositories that inherit an abstract class (that inherits another abstract class) which implements the interface? I will give you a simplified version of my current ...
-5
votes
0answers
34 views

Design Pattern for performing multiple actions for a request [closed]

I am looking for a design pattern to apply where each request, goes to stages where each stage consumes data from the previous stage if it was success, then after all stages succeed, respond back to ...
0
votes
3answers
78 views

Is this the return type covariance issue PHP faced when type declarations launched, violation of Liskov principle, or flaw in my pattern?

I've been using a somewhat odd yet effective pattern for a current use case. The one issue is that I'm getting an undefined method notice on a method that is unique to the subclass. The method of ...
3
votes
1answer
92 views

Is there a pattern for choosing one of a set of options at random when their selection criteria are equal?

I want to choose between several options, and if the criteria I'm using for selection happen to be equal, I want one at random (reasonably so, so it's equal-chance each time, rather than arbitrary). ...
-5
votes
2answers
81 views

How to design a terminal?

Good day everyone. I am planning to build a terminal, which will support common commands like ls, cd, cat, etc. But I am confused on how I should structure my codebase so that if in future, I decide ...
-5
votes
0answers
28 views

Middleware based frameworks alternative in NodeJS [closed]

According to some sources middleware based frameworks are hard to debug. Then why there are no NodeJS based frameworks using a different pattern? Is middleware the only option? If not, what are the ...
3
votes
1answer
73 views

Should a service object be transient or persistent?

In a typical server software design, business logic will generally invoke "services" (such as a database or web service). When I design such a system, I tend to think of each service as a singleton ...
-4
votes
1answer
35 views

Best way to structure reusable code using Node.JS, EJS, and front end JS?

I'm more or less learning the MEAN stack (have yet to start on Angular, so currently using straight vanilla JS for front-end) and part of what I'm building for my portfolio is a drag-and-drop form ...
3
votes
2answers
127 views

Refactoring for removing explicit object construction inside class

I'm wondering if there's a standardized name for the following refactoring: class Foo: def do_something_awesome(self): my_bar = Bar(42) return my_bar.reticulate_splines() Here class Foo is ...
2
votes
1answer
57 views

How to determine whether the postcondition of overridden methods is weaker or stronger if there is no return value?

To reiterate the question - what does it mean to have a weaker or stronger postcondition when overriding a method that only does side effects with another one that only does side effects? P.S. What ...
-1
votes
2answers
81 views

MVC who knows about whom?

In the Model-View-Controller pattern, I do understand the role of each component. The Model represents our application's domain model. The View presents this information and the controller ...
1
vote
0answers
51 views

Should class dependencies be organized in tree structure?

Is it doable, desirable to organize project classes, dependencies in Tree/DAG structure? To be more specific. In applications (not libraries) we have always some entry point, am I right? Some main ...
0
votes
1answer
90 views

Object Oriented Design of Callback Methods

Assume that there is a library and it provides an interface to its users in order to callback them. Users implement this interface and receive notifications from the library. Let's say, ICallback is ...
0
votes
1answer
43 views

Class Design question concerning adding a new “DRAFT” state to an object

We have some entities in our code: -"View" and View has some attributes and also contains one or many "SubViews" -And each "SubView" has some attributes and contains one or more "Tweet" entities. ...
2
votes
2answers
104 views

Algorithm for rule-based sorting?

I am trying to plant a garden. Certain plants are good for some plants and bad for others, and I am trying to find the best order of plants: most adjacent friends and no adjacent foes, as defined in ...
-4
votes
0answers
49 views

What is the right design pattern for me to abstract this class?

I am working with some code that takes advantage of ControllerContext. See: https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controllercontext?view=aspnet-mvc-5.2 My code looks something ...
5
votes
3answers
151 views

Approach for updating status of a function

When I call a function, I want to receive updates when the function reaches some milestones: def do_something(): start_with_something() # update for x in iterate_something(): # ...
23
votes
6answers
4k views

How to structure commits when unit test requires refactoring

I'm trying to get a review for my lists of pros/cons about how to structure commits that came out of a discussion at my work. Here's the scenario: I have to add feature X to a legacy code base The ...
0
votes
0answers
40 views

Am I structuring this correctly for a .net mvc web app based on onion architecture?

]1 I am new to MVC. Most of my career I have used Web Forms in Asp.net. Reading about MVC has been really confusing because from what I have learnt is that in Traditional MVC, models were supposed to ...
0
votes
0answers
49 views

Use of SQL Server with DDD in ASP.Net Web App

Hi I need to develop a new web application for my company and I must use DDD as per my senior-dev requirement. In addition I'm maintaining (adding new features and fixing bugs) a large brownfield web ...
0
votes
1answer
65 views

Is an antipattern returning differente objects in a single rest method?

I have seen around the Internet several rest web services with the following behaviour. In case there are any errors, they return a Error object, otherwise they return, say, MyClass. See the ...
-4
votes
0answers
34 views

What kind of design pattern do you use to add new entities to a collection?

I've got a collection with a certain type of entities. Now I want to iterate through this collection to find matchting entities (of the same type) and inject them to this same collection. So you ...
-2
votes
1answer
42 views

Design to method chain across packages

So bascially we have a library that contains a series of bifunctions passed in the metadata and datum looking like: Transform1: package transformation1; import com.fasterxml.jackson.databind....
0
votes
0answers
46 views

Clean architecture and state pattern

I am working in an GUI application that would work as follows: It will retrieve and save data from any of the following sources: A "Cloud Library": This library would get and save data to a cloud. ...
1
vote
2answers
55 views

How to agree on message schema in a Publish–subscribe pattern

I'm working on a project that uses PubSub(GCP), my question is not specific to GCP, it's more regarding to the architectural pattern(I'm used to statically typed languages, and I have a hard time ...
-2
votes
0answers
31 views

Can SOAP client can be considered as repository

I am developing a REST API, which will be used as a bridge/wrapper to get data from other legacy SOAP service, for this I have come up with a design as below with my previous experiences with DB and ...
0
votes
1answer
32 views

API Split for creating object with inheritance and behaviors

I have a web service which is exposed to UI owned by our team. This web service is responsible for creation of objects and saving it in the DB (NoSQL Database). The object being created has multiple ...
-2
votes
3answers
63 views

Is there a secure way to ensure a data in an API endpoint of mine came from an Instagram endpoint?

Is there a way through encryption/keys/jwt or anything else to ensure that the data being sent through a POST request is only data coming from another request I made on the client to a 3rd party ...
0
votes
1answer
38 views

What's a proper way to call a chain of methods that modify an instance attribute?

I've got an Algorithm class whose responsibility is to find if a given word is in a list of words. As part of doing that, the algorithm first has to lowercase the words, remove punctuation, and ...
4
votes
2answers
271 views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
0
votes
0answers
50 views

How do I decide if Domain-Driven Design would be applicable to this project?

I'm at the stage where I'm taking my MVP app and trying to refactor and structure it in a way that it is maintainable and extendible. I'm new to software architecture or design so I'm having early ...
-3
votes
1answer
43 views

Defining Database vs Service-level Entity [closed]

I have a demo application, which have customer and their order information. If I had a database, data will be stored in table as below, Customer : id | name | Address Order table : (for ...
-2
votes
1answer
59 views

How would you architect a simple cascading style sheet object?

How would you architect a simple cascading stylesheet like inheritance object? For example, I have Apple that extends Fruit. class Fruit { constructor() { this.total = 10; } } ...
4
votes
4answers
182 views

De-coupling business logic from POJO de-serialization design pattern

I've a JSON file which I'm trying to de-serialize into POJOs. public abstract BaseClass { private String baseClassField; abstract String execute(); } ClassA extends BaseClass public ClassA ...
0
votes
1answer
60 views

Problems with software layers in complex query methods

I desingned a rest api software with 2 simple layers: Controller and Service. The controller handles the coming http request and redirect to a service method. In the beginning of development every was ...
-2
votes
2answers
125 views

Dependency of program code on specific database values

I have two approaches to solving a problem but I don't know which one is better. I will give a simplified example. First approach The database will look like this: color | -------- FFFFFF | 0000FF ...
0
votes
0answers
22 views

Is it ok to have a mix of PubSub and Request/Reply in a WebSocket server (focus on unit-test)?

I'm using Node.JS to build a system where the data get consumed by WebSocket requests, instead of classical REST API calls. WebSockets were used for realtime bidirectional communication, but then were ...
0
votes
0answers
70 views

Best design pattern to map functions/wrap functions that will be used by client apps

Abstract: I'm attempting to create a "data interoperability API" or in other terms "high-level query interface API" that will be consumed by (data scientists, web apps, any who wants to query ...
-3
votes
2answers
68 views

What are some use cases for creating child processes?

I am trying to understand processes and their use in software engineering. Not processes in general but rather creating a process from within a program. It seems a really powerfull tool and i have a ...
-3
votes
1answer
35 views

What do you store first in a CQRS + ES architecture

I've recently started reading about CQRS, DDD and EventSourcing. From what I've read one of the best ways to do ES is to have an event store and then a regular DB or cache for easier querying. However,...
1
vote
2answers
69 views

design problem handling a dynamic object

I am writing an application for different geometrical types of fuel tanks. I have a design problem that only at runtime I will receive the exact type of tank from the end user; and I don't know how ...
-2
votes
2answers
94 views

Which Design Pattern to use to avoid conditional adding of elements to list?

I have code in the following form: public void drawObject(MyObject myObject) { RootElement root = new RootElement(); if (myObject.hasA()) { root.addElement(new XElement()); } else { ...
-2
votes
1answer
52 views

Design pattern for a switching between APIs with no code changes

I'm trying implement in JavaScript/Node.js a data upload functionality. I want to be able to switch between different storage providers, e.g. AWS, GCP, Azure, with no code change, for instance, via ...
-4
votes
1answer
32 views

Is there a design pattern for transferring “partial” or related data objects?

I am writing a program in Kotlin which parses some input data and writes it to a MySQL database (through JDBC). The database includes tables such as users and each table has a corresponding data ...
0
votes
0answers
14 views

How to preserve dynamic Configurations for a Process to historize it, load it and use it again for another process?

I want to Store a "Strategy" or "Set of Rules" on how a process is done. In a custumer Base, each User has certain orders. These orders depend on certain other Values. I want to store all User ...
0
votes
1answer
97 views

Fruit Ninja Design Decisions

I'm doing a Fruit Ninja clone in java (language not really relevant). It's not completed yet, but here is the point I'm in now: Currently I've: Difficulty interface, where several classes will ...
2
votes
1answer
83 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
99 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
243 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
63 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
2 3 4 5
77