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
76 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
vote
1answer
109 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
308 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
233 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
116 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
118 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
255 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 ...
43
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
178 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
192 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
151 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
236 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
97 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
75 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
177 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 ...
0
votes
1answer
81 views

Appropriate pattern for injector that sets a property and client that ONLY gets a property

Suppose I have a method in client code that expects an interface... void DoWork(IDataManager data) { //use IDataManager interface in the DoWork method } And the IDataManager interface looks like ...
0
votes
0answers
45 views

Data Mapper or Adapter when consuming 3rd party APIs

I consume 3rd party APIs which their format doesn't match my domain models. Is it okay to use the adapter design pattern to convert data to match or better to create a data mapper to convert 3rd party ...
2
votes
2answers
161 views

destroy object once it won't be used anymore in flyweight pattern

I want to use flyweight pattern to return the same instance of my object each time. public class ThingFactory { private static final HashMap<UUID, Thing> things = new HashMap<>(); ...
0
votes
0answers
34 views

How to store metadata (e.g. table name) for a model class?

What is the proper way to get a metadata of the type in languages that doesn't allow static methods/functions to be overridden? For example, I'm using Dart: abstract class Model { // Constructor ...
0
votes
1answer
75 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
0
votes
2answers
124 views

Card game with unique abilities - how do i implement this

I am making a card game, it is similar to Bang. You have a boss, which has some HP and you are getting cards with abilities, HP,DMG, etc. I want to make it as a .io game or maybe just a web ...
2
votes
1answer
121 views

C++ design pattern for template instantiation based on run time information?

Say I want to be able to create objects for a range of template parameter template<int a> class Myclass : public MyclassSuper{...}; And I want to create objects like Myclass<...
1
vote
0answers
61 views

Design Pattern to unify similar generated classes

I have a project where I work with generated classes for some web interfaces. Some of these classes are (almost) identical and most of the functionality I need them for only use the identical parts. ...
1
vote
1answer
18 views

How to organize work with objects containing different quailties of video

I run into a quite common case of handling Video files with different quality of a video, when the app (on android in this case) should save and use one or another video file depending on a user ...
0
votes
2answers
68 views

Should db commit and message-queue produce be one transaction?

I am making a microservice based architecture and I'm actively seeking antipatterns and trying to avoid them. In multiple scenarios, I have a database commit followed by a message that is produced to ...
5
votes
1answer
217 views

Why are the instance variables are declared as private in immutable pattern?

As the title says , Why are the instance variables are declared as private in immutable pattern ? I think that the keyword final is enough to avoid any changes that can be done to the value of the ...
0
votes
1answer
145 views

DDD & composition

I have a project to build, which has the following requirements: topup a wallet by paying money in exchange for credit; this has also the constraint of needing an approval from the finance team, if ...
6
votes
1answer
276 views

Implementing A “Draft” Mode For Posts

My team is debating how to transition a portion of our Rails application to allow "drafts". For simplicities sake, we can imagine a Post object where we want to allow a kind of draft mode. Our real ...
1
vote
1answer
58 views

What is a good way of satisfying open/closed principle in this case

I have a class that looks like this: class MyClass # takes an array of actions def initialize(actions) @actions = actions end def act @actions.each {|a| a.do} end end class ...
1
vote
1answer
142 views

Should an abstract class implement an interface, as opposed to defining its own abstract methods?

I'm defining a class structure for persisting to our cassandra database, and I'm unsure about using a combination of an abstract class and an interface. I have two concrete classes, one for persisting ...
2
votes
4answers
130 views

Make a class depends on its own ports instead of injecting dependency interfaces

I just have an idea about dependency management in Spring IOC environment that seems to be better than the typical approach, but I am not sure because I can't find any references or example out there ...
1
vote
3answers
243 views

Determining response codes from void functions OOP

I am trying to create a Put endpoint using rest. Let's say that under the link /addresses/12345 I am trying to add a new address (if that id doesn't exist) or I'm trying to update it if it does ...
1
vote
2answers
140 views

What is the best model to catch DB side error?

We have a web application that all update, insert and DB operation procedure handle via SQL Server DB 2017. What is the best way to handle and get error (in Web-app or SQL server error handler?). for ...
0
votes
1answer
101 views

Re-usability in C++ using Interfaces and External Configuration

I am practicing professional C++ by building a differential drive robot that applies a Go-To-Goal Behavior. What is I have written so far is an Agent that consumes the following interfaces: ...
0
votes
2answers
154 views

What is the difference between singleton pattern using inner static “Holder” class and “Instance” variable

I have encountered two patterns to make a singleton class Holder class public class Singleton { private static final class Holder { private static final Singleton INSTANCE = new Singleton(...
0
votes
3answers
99 views

Can I make other developers aware that they can define certain functions for extra-functionality even if they're not required?

The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface), I check if ...
4
votes
3answers
369 views

What to do when interfaces force me into violating the single-responsibility principle?

(The code I'd have to post is huge, I'll resume to just function names) I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view ...
0
votes
0answers
25 views

Can MVC be utilized via foreign function interface?

As far as I understood, MVC has the biggest advantage in creating a separation of concern and making three components decoupled as much as possible. All of the examples I saw were in a single ...
0
votes
1answer
123 views

How can I vary the distance function in my code?

I have a simple design question. I have a tree based C++ class. It needs to use a distance function in order to calculate nearest neighbors. But the distance function is available from an external ...
2
votes
1answer
70 views

How to implement acquaintance and aggregate as described by the Gang of Four

Is the following implementation in PHP correct? I focused on what they say about the lifetime of dependencies: “Aggregation implies that an aggregate object and its owner have identical lifetimes.“ ...
1
vote
1answer
92 views

How should I integrate routine history tracking feature with the routine itself

Let's say I am writing code to run a machine similar to a 3D printer and I have a routine like: machine.moveTo(x1, y1); machine.alignByCamera(); machine.heatUp(); machine.extrude(amount1); machine....
-4
votes
2answers
100 views

Observer pattern IS-A Command pattern?

This is Observer Pattern This is Command Pattern, with a highlight to make it similar to Observer Pattern The only differences are: Receiver IS-A Invoker in Observer Pattern Observer Pattern knows ...
0
votes
1answer
109 views

MVC Controller calling UoW (unit of work) directly instead of going through Service Layer

Currently im injecting my Unit of Work inside the controller. I figured out that in most of the designs, controllers calls the service layer and service calls the repository/DAL layer. Most of the ...
0
votes
1answer
237 views

Injecting DAO dependencies into Service Class in Core Java

We don't have any frameworj like Spring where we can inject dependencies using annotations or xml file. We have handler classes, service classes and dao classes. Handler classes access service which ...
2
votes
1answer
101 views

Design approach for extending class functionality - Embedded C++

For my company i am refactoring our embedded C/C++ code base to increase re-usability for commonly used functionality. Currently i am refactoring our command line interface but i ran into a design ...
0
votes
2answers
275 views

About Observer interface in Observer Pattern of GoF?

I'm reading about Observer Pattern of GoF, the UML in the book: From the above diagram, how many Observer interface are there in a system if I have two different ConcreteSubject classes? Would they ...