Questions tagged [design-patterns]

A design pattern is a general reusable solution to a commonly occurring problem in software design.

-2
votes
0answers
22 views

How to cache multiple version of site [on hold]

I have a site with feed of user notes, and i want to show to users only top 100 notes (paginated by 10 per page). Every note has some tags (like subreddits on reddit), and every user can add some tags ...
2
votes
1answer
99 views

How to make updates to data and return list of updates without breaking Command query separation or DRY?

I have a use case to make updates to a slightly complex JSON object and then return the list of changes made (not the updated data). The process of finding the list of changes is extremely similar to ...
2
votes
1answer
74 views

What to do when you want to apply some common functionality to some specific methods?

I am trying to figure out a design pattern to use (if any exists) to a situation where I would be re-doing some functionality across a bunch of classes. Below is a (simplified) overview of the problem ...
1
vote
1answer
26 views

Reduce duplicates in outbox pattern in event driven systems

Trying to implement the outbox pattern for an event driven system. The outbox pattern in a nutshell is a way to ensure system events are sent to the event log/queue/bus at least once (using the term ...
0
votes
4answers
118 views

Should validation be inside or outside function?

Which one is better? A if ( complexDataCheck(...) ) { doJob(...) } vs B doJob() func doJob(...) { if not(complextDataCheck(...)) return error; ... } In A, the function does one and ...
-2
votes
3answers
163 views

Code design: introduce new method vs add optional parameter to existing method

In JavaScript (ES6), I can have optional function parameter with default value. So to add a new behavior to the existing code base, I could either introduce new method(s) or extend the existing method ...
-2
votes
2answers
69 views

What are some examples of changing Commands at run time? [closed]

I've been reading on the Command pattern. One of the advantages listed is that you can change the commands at run time and avoid hard coding invokers to receivers. But when do you really need to do ...
-1
votes
1answer
61 views

Designing command and factory pattern with large conditions

I working on a project requiring quite a lot handlers to handle requests. In general, i'm comunicating with a communication card, receiving requests from any source (User Interface, Server it doesn't ...
0
votes
1answer
28 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
-3
votes
0answers
45 views

Are my UML's understandable and do they follow the UML conventions? [closed]

I'm new to software modeling and was hoping someone could walk me through mistakes I've made. I'm trying to show how my parser for our game is working. Said in words, the parser is supposed to take ...
3
votes
3answers
154 views

Is this a good method of separation?

I am creating a web application that is tiered in the following way: Controller > Service > Repository I have a ProductsController which has the following action: [ValidateModel] [HttpPost] public ...
-3
votes
1answer
79 views

Taking over a project. Should I scrap and rebuild? [closed]

I'm taking over an Opencart solution for a client. This is for my capstone at College. I'm to create a simple CRM (Customer Relationship Management) software that will live as a single page ...
0
votes
0answers
27 views

Handling resumable message stream (queue) pattern

My question is actually quite generic though I'm going to use a particular technology Mongodb Change Streams. Change streams in Mongo allow to get message stream of requested changes in a db ...
-2
votes
1answer
101 views

What name would you give to this class design? [closed]

I have inherited a legacy code base and see a lot of classes that implement methods in the following way. class InvoiceCreateService { private $order; // Domain object public function ...
9
votes
5answers
2k views

Can we completely replace inheritance using strategy pattern and dependency injection?

For example: var duckBehaviors = new Duckbehavior(); duckBehaviors.quackBehavior = new Quack(); duckBehaviors.flyBehavior = new FlyWithWings(); Duck duck = new Duck(DuckTypes.MallardDuck, ...
0
votes
1answer
31 views

What is a good strategy for managing PubSub subscriptions

I am working with Reddis but this could apply to any PubSub implementation. Essentially we are trying to implement an event system using Reddis's PubSub capabilities. As an example UserA creates a ...
0
votes
1answer
118 views

Relating subclasses of two classes

Suppose I have the following problem: I have Users who work in Departments. A user can work in multiple departments and a department can have multiple users. Each departament gives to its users only ...
6
votes
6answers
511 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
0
votes
1answer
27 views

Venue Reservation System Logic Approach/Clarification

I hope this is the right place to ask since this is a programming related question. I’m developing a venue reservation app (similar to booking.com) and am almost done however I have 1 request for ...
0
votes
1answer
54 views

Update Entity for Repository Pattern and UOW Pattern C#

In one mock solution, I have created 3 mock projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer. I haven't yet to add ...
0
votes
2answers
76 views

What are the relations between the presentation/application/data logics, client and server, and MVC?

I appreciate if someone could clarify my confusions about the following quote from Distributed Systems, by Coulouris et al: Consider the functional decomposition of a given application, as ...
0
votes
1answer
43 views

How to associate tree nodes with other objects before they have unique identifiers

I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node ...
1
vote
1answer
116 views

Contract based programming with verifications

I have a large project that is build contract based, where all functions verify input parameters and return values. But there are also cases where they for example verify that a call to a function is ...
0
votes
2answers
35 views

Force State changing of an Object only from Holder

Suppose I have a Button class with a color attribute. I also have a Canvas class which stores all Buttons. Every time a color is being changed, some side action must take place (in this example, for ...
2
votes
1answer
89 views

Microservice API Design Pattern

I'm new to the application architecture world. I walked through Docker's sample voting app, and see that basically everything that can be made into a modular piece, is made into one. I'd really like ...
0
votes
0answers
31 views

Is Unity Container Property Injection following Bridge Design?

I have following code written on top of Microsoft Unity. This is the implementation of property injection. I recently gone through a Bridge Design Pattern that separates abstraction from ...
2
votes
1answer
280 views

Two-level concepts

I find myself lately implementing the same concept twice, once at a low level and once at a higher level. Let me see if I can explain it... For example, given the notion of a database, I have one ...
0
votes
1answer
184 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
3
votes
1answer
162 views

Is Enum Polymorphism bad for DAO Methods?

I have been going back and forth in a discussion about polymorphic enums to call different DAO methods depending on enum entry, and I haven't been able to get a common agreement on this subject. Lets ...
2
votes
1answer
172 views

How can I allow interaction between user-only modules & admin-only modules without polluting with privilege checks?

Important note: This is PHP (5.3+). PHP is stateless and everything you do dies when the request is over unless saved to a persistent storage, but if the answer provided gives me pseudo-code, I'd also ...
0
votes
1answer
65 views

Architecture for message processing with scheduling, at scale

I have to design the architecture of a system that processes messages in a distributed manner. If this were the only requirement, I would use a message queue like Kafka and distribute the work with ...
-1
votes
1answer
110 views

Determine if action is possible depending on many objects and notify state changes [closed]

In the game I'm developing I need to determine if an action is possible. Whether the action is possible is dependent on a number of factors spread across many objects (ActionDeterminers) in the game. ...
1
vote
1answer
94 views

Simple Audit Logging Design

I have a C# MVC application. One of the requirements of the application is to maintain an audit log of everything that happens to a particular 'entity' page. To make the example concrete, lets say ...
0
votes
4answers
301 views

Is Template design pattern a bad practice due to inheritance?

I have been using Template Design pattern in my code for implementing CRUD procedures for different resources. There are some steps which are same for many resources and some which need some addition/...
2
votes
2answers
231 views

What pattern lets each of multiple “voters” decide on a central status?

Imagine there's a boolean status variable that is either running or stopped. This variable is running by default and comes together with a deactivator function. When a client calls the deactivator ...
1
vote
0answers
108 views

How to store relational data belonging to different client customers?

My users will be businesses with a small number of accounts each: e.g. Business #1 with 3 users, Business #2 with 5 users, etc. I am trying to determine the best way to organise the relation (on ...
0
votes
2answers
111 views

Passing data through public members

I am working with an existing numerical model implemented in C++, and I don't have much of a background in software design. This model reads in many (~100) of structured text files, performs numerous ...
0
votes
0answers
41 views

How to compose load balancing and circuit breaking for external data source

So I have this issue. My website uses data, that is scraped from a different site - sports results. This data can update in relatively random intervals, but I do not care if my data is a bit stale - ...
1
vote
1answer
104 views

Why using ViewModel when using also Repository?

I read this guide about recommended app architecture for Android. Here is a graphical summery: The role of ViewModel is clear, but I don't understand why we need it if we use Repository. The purpose ...
1
vote
2answers
249 views

When to use Factory design pattern instead of Dependency Injection?

I'm quite inexperienced in design patterns and while I was studying them I got confused about the application of the Factory pattern. Wouldn't DI decouple the classes more than factory would do it? Or ...
42
votes
4answers
7k views

Exception propagation: When should I catch exceptions?

MethodA calls an MethodB which in turn calls MethodC. There is NO exception handling in MethodB or MethodC. But there is exception handling in MethodA. In MethodC an exception occurs. Now, that ...
-1
votes
4answers
176 views

Avoid method dependance on object being populated

Is there some sort of pattern for enforcing the calling of a populator method before any of the rest of the interface is used? I say this because it is not generally a good idea to put something ...
1
vote
2answers
154 views

What do you call a class that can be disabled [closed]

Is there a design pattern that fits this description? A factory that creates classes that can be disabled and enabled. The users of the class don't know if the functionality is enabled or disabled--...
4
votes
1answer
189 views

Design pattern for selecting data

I have implemented algorithm BFS(Breadth First Search) using a neighbors list ADT for scanning a graph and gathering information about it and answer questions. I have function called BFS which ...
2
votes
1answer
148 views

Unit conversion of data

My team is developing a web application, where we have in the requirements to display the data in multiple unit which is set by the end user. Where should we write down the unit conversion logic, on ...
0
votes
0answers
65 views

Should modules strive to export only one thing?

Ideally, functions should do one thing well, and only one thing. Does the same thing apply to what a module should export? Of course, modules aren't always the same thing as functions, but they often ...
4
votes
2answers
235 views

Does software architecture depend on framework being used?

When I was building my backend API I used Django combined with django-rest-framework (DRF) because it was the easiest and fastest way to create what I needed. And I haven't thought about an ...
0
votes
2answers
95 views

Would you use the mediator pattern for this scenario?

I'm wondering if you would use the mediator pattern on the following scenario. First of at all, the program must call an API, and persist this response on somewhere (it could be a database, a file, ...
0
votes
1answer
72 views

REST API Client Library Design

I'm working on a reusable client library to abstract a REST endpoint that we use in many of our in-house applications. It is actually split into 3 APIs, and certain endpoints/resources require ...
3
votes
2answers
125 views

Domain driven design project structure [closed]

I have recently started reading about domain driven design and most of the places it's explained or discussed more in conceptual terms. Being a design philosophy it helps to understand the concepts ...