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
0answers
41 views

Multiple endpoints but share the business layer

I am looking at a code base that has multiple APIs and traditional server rendered website. The business logic is duplicated between each of the APIs. I would like to clean this up and share the ...
-2
votes
2answers
107 views

Where to place exception handling while using Decorator design pattern

How to design a service layer structure that will be resistant to exceptions. Let's say I have a simple OrderService service, this service performs basic operations - saving an order. public interface ...
0
votes
4answers
240 views

A case when you can't make processing idempotent

I have just been confirmed for an interview and one of the hint questions given by the recruiter was: "Explain Idempotency and a case when you can't make processing idempotent" I understand ...
4
votes
1answer
237 views

Dependency Injection: What are advantages of using a framework? [duplicate]

Introduction and Question I understand what the advantages of dependency injection, e.g. constructor injection or setter injection and that it is one way of doing inversion of control. I also ...
3
votes
2answers
111 views

Best approach for inter-process task queues

I have an application made up of multiple processes/workers/services which need to send messages to each other that represent units of "enqueued tasks" to be done. I am trying to find the ...
-2
votes
1answer
83 views

Scaffold design pattern [duplicate]

I'm looking for something that might be described as a "Scaffold design pattern". I'm in the process of resurrecting an old piece of working but very buggy code that implements a Finite ...
1
vote
2answers
348 views

No trivial god-class refactoring

Consider you have the following code: class UserContainer { List<User> user; //some methods to get specific users, for example users, which are higher than 1,70meters } The User have a ...
1
vote
1answer
2k views

Does this diagram give a good representation of the MVVM pattern?

I am having a really hard time understanding the basic structure of the Model, View, View Model pattern. I have honestly been pretty ignorant of design pattern conventions until recently. My formal ...
0
votes
2answers
47 views

Handling a column in a database which can change on external conditions

Let's suppose we have a table of products, similar to this one: ProductId ProductFriendlyName ProductPrice 84 Coke can 2 When a specific condition applies (the actual condition isn't really ...
1
vote
0answers
31 views

Managing the output rate for a queue triggered service

I have a service which is triggered by messages from three queues (which are populated by different topics), and writes the processed results to another system (say DB service) synchronously. The ...
0
votes
0answers
33 views

Am I doing Unit Of Work or Context Object pattern against my API, or none of em?

I have created a "simple" C# client library for an HTTP based API (So, think kind of REST.. but yet not.. but that aint important for this discussion anyways, but might be important for some ...
0
votes
2answers
101 views

Good design for a class with multiple methods to test but one public method

I've been trying to refactor some existing code which is in essence a giant nested procedural call inside what should otherwise be an object oriented architecture. The entry point to the relevant code ...
4
votes
3answers
229 views

Passing object or using the field

I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class? Using the field: ...
0
votes
1answer
54 views

Pipeline's outputted data mirroring pipeline's architecture

I'm building a pipeline that scrapes data on entities, to keep things generic, let's call them Widgets. Data on Widgets is currently unorganized and spread across various sources, including source ...
0
votes
2answers
102 views

Is my analogy of an Abstract Factory valid?

After working through several tutorials and reading various responses on this site, I believe the Abstract Factory pattern would work well for a current project. I am seeking the opinions of those ...
0
votes
1answer
103 views

What design pattern (if so) did I apply? How can I further improve it?

Suppose I have a program.c that needs element_123 to do some operations, and element_123 can be accessed by including agent.h /*program.c*/ #include "agent.h" uint32_t element_123 = 0; ...
1
vote
1answer
73 views

Does it make sense to have a facade centralizing events too?

From my understanding a facade is a class with the sole purpose of simplifying the use of a specific system/module behavior (its methods). It should not contain any relevant logic of the underlying ...
-1
votes
2answers
106 views

How to deal with classes with same purpose from different libraries?

I have a question regarding software design/architecture. Are there any best practices or design patterns regarding the usage of classes with the same purpose from different libraries? Let's imagine ...
1
vote
2answers
66 views

c# template method pattern design question

I'm currently in a situation where I have multiple derived class types(just one is shown in the example below) that need to apply some logic before and/or after calling a method implemented in a ...
0
votes
1answer
77 views

Should there only ever be one instance of a ViewModel object?

Assume a rather simplistic model: class Person{ static List<Person> LivingPersons String Name List<Person> Dependents } From this it can (hopefully) be seen that a single ...
4
votes
2answers
154 views

GoF Builder Pattern Applicability

The book Design Patterns: Elements of Reusable Object-Oriented Software says to use the builder pattern when The algorithm for creating a complex object should be independent of the parts that make ...
0
votes
1answer
77 views

Python: Function pipeline with multiple return/input values, or use OOP? Best Practices?

I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways. Looking for the best practise on ...
6
votes
3answers
5k views

Low Coupling: Single Responsibility Principle vs Cohesion

I've read several articles on SRP and cohesion, and they seem to contradict each other as far as low coupling is concerned. Articles on cohesion argue that putting closely related responsibilities ...
6
votes
3answers
5k views

Clean architecture, CQRS, and authentication?

I'm working on implementing my first clean architecture and CQRS application, I've stumbled across a bit of logic that's leaving me a bit stumped. I'm working on integrating authorization and ...
1
vote
0answers
67 views

Visitor pattern with internal iterators

I'm trying to understand the following description of implementing the visitor pattern with an internal iterator. It is from the GoF's Design Pattern Elements of Reusable Object-Oriented Software book ...
0
votes
0answers
68 views

Can someone suggest what pattern I used mistakenly and is it correct in this situation. Any alternative?

Client_1 uses --> IService_1 and thus Service1_impl public interface IService_1 { void DoTask_1(); } public class Service1_impl : IService_1 { private readonly IDepService_1_v1 ...
2
votes
1answer
243 views

What is the name of this pattern / style?

We have a "workflow orchestration" system at work. It works something like this: You configure what to run (in a database table), such as: NameOfStepATHingToRun ="weather_data" ...
17
votes
3answers
20k views

Model-View-Controller: Does the user interact with the View or with the Controller?

I have recently learned about the MVC design pattern. I'm learning from the Head First Design Pattern book. According to this book (if I understand correctly): The Model is most of the application ...
36
votes
3answers
26k views

Can someone explain in simple terms what is the disruptor pattern?

I would like if you could explain to me in a simple way how does the disruptor patter work. This concept has been elusive to me as of know. Perhaps with your help I could comprehend it.
1
vote
2answers
671 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 ...
0
votes
0answers
51 views

Design pattern for intercepting requests to an API (Rule Engine)

I want to use a rule engine to centralize business rules. My rules require information not typically owned by systems that call the rules engine. I don't want to complicate these systems (System A and ...
1
vote
2answers
86 views

Good OO design pattern for variant return type needs

I've got a validation function something like this (pseudo-code): public function validate(Thing thing) { if (thing.a != "a") { return false; // most of the time } if (...
1
vote
1answer
282 views

What is the currently best C# implementation for a Producer/Consumer scenario?

I have a relatively simple task where I need some 10 consumers to consume work to be produced into a queue, continuously. This is my first time implementing this design pattern, so I have been ...
2
votes
3answers
267 views

Swappable state object or decoupling data and functions

I come from OOP pradigm and I also know a bit about functional programming and its advantages. Over time I came to like the separation of data and transformations that are applied to it using pure ...
1
vote
2answers
92 views

Visitor design pattern usage

I have been implementing a software driver for an external (from my microcontroller point of view) chip communicating with my microcontroller over I2C. From the higher perspective the chip is a ...
14
votes
5answers
3k views

According to Demeter's law, is a class allowed to return one of its members?

I have three questions concerning Demeter's law. Apart from classes which were specifically appointed to return objects - such as factory and builder classes - is it okay for a method to return an ...
3
votes
4answers
2k views

Are factories required when doing dependency injection?

I'm trying to refactor some code, so it uses dependency injection. Take this (non-sense) example class: class Foo { protected $min; protected $max; public $bar; public function __construct($...
0
votes
1answer
1k 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 ...
0
votes
3answers
84 views

How do you structure components to objects so they are more decoupled and non dependant?

I want to setup my objects to be composed of components that can be added and removed so I have more flexibility in how I set them up. A simple example would be some object that can have components ...
1
vote
1answer
135 views

Why we don't use array of classes instead of Chain of Responsibility technique

I am new to SE. Recently I read about the Chain of Responsibility pattern, so basically what it does is: it creates a class that has some methods and also next class (next chain block), so when it ...
-2
votes
2answers
82 views

How would you create abstraction for event holding only Ids - references to other objects

class DomainEvent { } and then I have different events with following structure: class SomeEvent extend DomainEvent { private UUID orderId; private UUID orderlineId; private UUID productId; ...
68
votes
5answers
26k views

What is inversion of control, and when should I use it?

I am designing a new system and I want to know what inversion of control (IOC) is, and more importantly, when to use it. Does it have to be implemented with interfaces or can be done with classes?
0
votes
1answer
168 views

Modular code how do they really fit together?

Let's say I am developing an ecommerce application. And I have modules organized in certain way. Products Coupon Tag (can be used as brands and linked data) Offer Now what I want to achieve is user ...
0
votes
1answer
43 views

ORM patterns: entity properties that depend on collection loading

Given a couple of entities, Invoice and InvoiceRow, I want to calculate the total amount by summing up each row's amount. public class Invoice { [Key] public int? Id { get; set; } public ...
-2
votes
1answer
147 views

toppings in pizza factory?

Going through Head First Design Patterns, and their Pizza factory example, it seems that there is no room for specifying toppings. In general, if I have a process which contacts different APIs which ...
0
votes
1answer
318 views

Machine Learning pipeline design patterns

In machine learning we have modules that perform operations on data in a sequencial manner. Modules are generally the following: Data Collection Module: Takes raw data from a resource (filesystem,...
1
vote
4answers
4k views

Builder pattern: How to verify required fields before runtime

A language agnostic approach since I see this problem in both compiled and interpreted languages with the builder pattern. Let's say I have a Model that has 10 required fields and 5 optional fields. ...
0
votes
3answers
138 views

Separated implementations or one with all functionalities

I am currently creating Excel import modules for some complex data. I didn't plan it well and I have met code reuse issues. I have made first modules and I realized that next modules will need some ...
2
votes
3answers
1k views

Multithreaded UI desktop application issues

I am involved into development a rich UI project: desktop windows application. Application uses asynchronous invocations and in its turn it should be ready to process external messages (events). The ...
1
vote
2answers
1k views

Simple Snake Game in C++

I posted this question originally in Code Review, but then thought that I could possibly get more feedback about the design here. I just finished writing a simple Snake clone in C++ with the goal of ...

1
3 4
5
6 7
84