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
48 views

C++ pattern for compile-time configurable class functionality

Due to resource limitations (embedded), I want to make some functionality that a class provides optional. The decision to include this optional functionality should be made at compile time. For ...
0
votes
4answers
102 views

What if there is specific logic for one particular value of an enumeration class?

Background: I have seem some argument for using enumeration classes instead of enum in C#, in particular, this section from a book available at MSDN. On the references there is this "Enums are Evil" ...
0
votes
2answers
33 views

DDD and Infrastructure micro-Services - how should the interface be designed?

We've extracted our email sending into an EmailService - this is a microservice that provides resiliency and abstracts the email logic into an Infrastructure service. The question is how the ...
-2
votes
1answer
45 views

How to create a league scheduling algorithm?

Our requirement was to create an auto fixture generation tool that creates fixtures for a league with any number of teams, and where they have a fair distribution of home and away games so that: ...
0
votes
1answer
53 views

Granularity of the Single Responsibility Principle [duplicate]

This is a related question and the OP appeared to go with extreme levels of granularity. The answers gave a good overview but I gather it's still somewhat down to personal interpretations/situations ...
2
votes
3answers
189 views

Which is a better method name? GetById(int id) or Get(int id) [on hold]

Has there ever been a consensus on which convention is "better": User.GetById(int id); or User.Get(int id); i.e., is User.Get(int id); not descriptive enough? Or does is the parameter implication ...
0
votes
0answers
25 views

How to merge data models of two web applications? [closed]

Say company A and B both offer two distinct web applications, both with their user accounts for log in and their own data model in general. Now company A takes over company B. How should company A ...
1
vote
3answers
176 views

Use just one parameter for all dependencies instead of many?

I understand that having 3 or more parameters as dependency is a sign that the class may be doing too many things, however there are cases that the class really needs more than 3. My question is, is ...
5
votes
8answers
427 views

How to apply OOP to real world examples without putting all logic in Manager classes?

I'm lately trying to implement a specific problem using an object-oriented approach. I get the main principles and its advantages, but I fail to apply it to a real world problem. Most examples one ...
1
vote
2answers
30 views

JHipster generated endpoints adds header messages

I'm adding new functionality to an existing application it was done using JHipster. I've notice that some endpoints follow this pattern: return ResponseUtil.wrapOrNotFound(updatedUser, ...
0
votes
0answers
84 views

Code Design: Repeatedly doing the same Boolean check with Stream Writer

I have several areas in a program where I am doing the following check on the same two booleans, but each spot has different text being written to a file via Stream Writer based on the value of the ...
0
votes
0answers
53 views

Design pattern for exposing static functions in C/C++ only to unit tests [closed]

I have some static free functions (the don't belong to a class) in a C++ file. I want them to still be only visible within such module and to be free, but I want to test them with unit tests as well. ...
2
votes
0answers
58 views

Object attributes as special parameter objects in python

I am writing a library that can be used with some GUI and would like to be able to build an interface where user can see and/or change most of the object's parameters, and also write some of these ...
0
votes
1answer
60 views

c# Fluent Builder and invalid object state

I have a question about Fluent Interface Builder. I have a simple object like this: public class Person { public string Name { get; set; } public string Surname { get; set; } public int ...
0
votes
0answers
58 views

How to control JavaFX's animations execution order when animations “queue” is being altered in run-time? [migrated]

What is the proper way of handling synchronization between GUI animations' execution order and the user's dynamic input? More specifically, I would like to know how to enforce some logical ...
0
votes
0answers
80 views

C++ loose coupled library design [closed]

Let's see if I can explain this properly. I have been told to refactor/redesign/rewrite a desktop application. I am starting by the library part first. Everything is C++. I came up with a new design ...
0
votes
1answer
75 views

Best design for a AMQP work queue

I have a system where a user uploads a file to import some users but it's necessary to do some validations and this take some time. I would like to create a work queue with RabbitMQ and the user will ...
0
votes
0answers
22 views

Design pattern that can be used for checking and handling a change in version number for incoming JSON message into data stream?

I have a Spark Streaming Job which processes messages coming from Kafka. My incoming json that I process sort of looks like {"sv" : 1.0, "field1" : "some data"} The only thing I do is put these in ...
0
votes
1answer
177 views

Dependency injection: Is there a better way than new A(new B(new C ()))? [closed]

I'm just learning about dependency injection. Unfortunately, I don't have the luxury and time to learn a DI framework right now so I am attempting to do DI through some simple means. Say I have an ...
-2
votes
2answers
70 views

How do I model all the different states of a widget for testing?

Say I am a QA person so I have no control over the complexity of the code in the following example. I have a datatable widget with many different filtering and searching options. All the columns on ...
2
votes
1answer
138 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
86 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
42 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
143 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
174 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 ...
-1
votes
1answer
63 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
33 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
3answers
164 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
84 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
29 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
114 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 ...
10
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 mallardDuck = new Duck(DuckTypes.MallardDuck, ...
1
vote
1answer
55 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
140 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
537 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
30 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
59 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
101 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
45 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 ...
2
votes
1answer
139 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
41 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
95 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
32 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
286 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
201 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
163 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
174 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
74 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
103 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
306 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/...