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 vote
1 answer
82 views

Proxy Pattern in Python

I'm reading a book on design patterns. On proxy pattern the code are following: class SensitiveInfo: def __init__(self): self.users = ['nick', 'tom', 'ben', 'mike'] def read(self): ...
0 votes
3 answers
129 views

What pattern is a function that returns a component?

Ok I have a bunch of components that all have the same logic but have different css classes. So I wanted to create a sort of factory function that takes the names of the classes as its argument and ...
  • 155
5 votes
3 answers
109 views

UML Composition parent association end

The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent (association). However, shouldn't ...
1 vote
1 answer
130 views

UML Composition parent multiplicity

The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent. However, given that: a ...
0 votes
2 answers
104 views

How to solve an issue when a decorator needs variables from the base class?

I have a service class that does some magic. I want to introduce a new type of functionality - raise an event. I am absolutely sure that decorator pattern is great for this scenario. The problem is ...
  • 451
-1 votes
3 answers
352 views

What is the difference between Facade and God?

A Facade is a higher level API over a whole subsystem. A God is class that violates SRP. Where do we draw the line? Does the following code represent any of the two: enum UnitType{Demon, Paladin}; ...
  • 6,955
1 vote
2 answers
109 views

Difference between Front Controller and Mediator patterns [closed]

I was reading about these patterns and noticed that they seem to be basically the same, but in different contexts? If that's the case, why isn't Front Controller just considered as a Mediator pattern ...
1 vote
1 answer
301 views

MVC-like architecture: Model-Controller communication of results/status

I'm struggling on designing a solid architecture for my project. In particular, I don't know how to handle the communication between the models and the controllers. My goals are: Following the ...
2 votes
2 answers
119 views

Procedural configuration code to object oriented code

Lets say we have an Webserver-Framework and a Database-Framework, and now i want to configure that Webserver and the Database, then it could look like the following class Start { public static ...
1 vote
0 answers
134 views

Terse finite state machines in Haskell

I'm writing a parser for a markup language in haskell, and a finite state machine fell out of my ideal API. I have code that looks a bit like this: Token = BoldWord String | Word String | ...
  • 281
-4 votes
1 answer
102 views

design patterns in functional languages.... or in compilers [duplicate]

It seems that design patterns are actually linked to some C++ or Java object models (e.g. they might not fit to Ocaml objects, or to Common Lisp Object System). Or at least tied to a specific ...
3 votes
3 answers
328 views

Dispose pattern without unmanaged objects

I've used the wellknown Dispose Pattern in .NET several times as described in the official docs. Now I have the following, rather simplified code: public class FirstForeignDependency : IDisposable { ...
  • 139
1 vote
1 answer
1k views

Websocket client reconnection best practices

I wasn't sure whether to post this on StackOverflow or here. Let me know if you think it belongs on StackOverflow. I have an application that will run semi-persistently, i.e. all the time. The ...
1 vote
0 answers
62 views

Issue implementing the Command Processor pattern using MVVM for WPF?

I'm trying to implement the Command Processor pattern using MVVM for WPF. The Command Processor pattern that I'm roughly following is the one described in the book Pattern-Oriented Software ...
  • 133
1 vote
1 answer
144 views

State Pattern when the Behavior in Object of Type A is Dependent on the State of the Object of Type B

I have used the state pattern for my web application where a user can be in one of three states: activated, required_activation and suspended. I have created 3 states classes as given below (source is ...
  • 137
2 votes
1 answer
133 views

Data visualisation application for WPF and MVVM

I was wondering what is the best approach for a Data visualisation application for WPF and MVVM The key points are: The data is loaded, or needs just a little preparation such as pulling out ...
-2 votes
3 answers
79 views

Design consideration-To add or not to add a related variable in a class

I need something clarified. I have been having a discussion with someone and we have conflicting arguments. Hence, I came here to ask looking for your insights. Say we have to implement our own stack ...
0 votes
1 answer
169 views

Wrapping the UI framework

I want to write an application where I would delegate certain functionalities to 3rd party libraries. To make sure the code remains modular, I want to put these libraries behind an interface so I can ...
0 votes
1 answer
78 views

Approach for store multiple relationships POO objects in relational database

I'm developing a system in which a ClassA object can have multiple ClassB and ClassC objects. And for store these objects in a relational DB model I create the following tables: This is a simplified ...
  • 177
0 votes
0 answers
93 views

Is Controller a special kind of Indirection in GRASP Design pattern?

This is Indirection according to Wikipedia Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Controller seems ...
2 votes
1 answer
224 views

In an MVC Application, What Goes Where?

In an Model-View-Controller (MVC) design pattern, What goes where? What code goes to model and to controller? I know (do I?) that business logic should be define in a model, but a lot of example I ...
0 votes
1 answer
84 views

Strategy pattern with implemented public method

New to design patterns so my question maybe silly. I want to use strategy pattern for returning data from a databases in the same format. Nevertheless it varies the query on the underlying database ...
0 votes
1 answer
64 views

Interface design for container that holds different instances derived from a common type

I'm currently designing an interface for a container that is supposed to store references of different instances that derived from a common supertype. An analogy of it would be as following: Suppose ...
0 votes
1 answer
69 views

Integration with stripe, have a single source of truth or have info of the user status in our DB

So We're integrating our application with stripe and we have different products There are 2 options : Have stripe as a single source of truth, anytime we need to check the permissions of a user we ...
  • 123
3 votes
1 answer
138 views

Command pattern and object model integration

In a document editor application, is it better to implement the command pattern as a layer on top of the object model, or to deeply integrate it into the object model? If commands are a layer on top, ...
  • 141
3 votes
1 answer
82 views

Structuring user story tests with variations

I'm writing the sort of tests which go through a whole user scenario e.g. User clicks "edit profile" User edits their name etc. However, I find myself needing often needing to test small ...
  • 1,045
0 votes
1 answer
252 views

Is this dependency propogation an anti-pattern, and how do I remove it?

Module A contains a gap buffer for manipulating text and some associated methods. Relevant to this question is the dependency on a Module B, used for syntax highlighting of text. Module A also ...
  • 281
1 vote
2 answers
153 views

Connecting classes by passing method references

I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass ...
  • 21
0 votes
0 answers
22 views

Controling one stream pipeline (out of two synchronous stream) based on time

[ I am not a SE so my terminologies might be absurd ] Background I have two stream: a and b. Stream b comes to the processing pipeline and after some transformation gets into the database directly. ...
  • 101
0 votes
0 answers
94 views

React Redux chain-of-actions pattern - should I create new synchronous middleware for synchronous actions?

I am creating React Web application with Yii2 API and Redux-Saga which calls Yii2 API (asynchronously). I am stuck with one especially large and complex user action (initiated by the selection of good,...
  • 1,009
3 votes
4 answers
431 views

Is it a bad practice to have an interface method to tell whether it can handle an object?

interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; ...
2 votes
3 answers
520 views

What we called this design pattern and it is same as strategy pattern?

abstract class BaseService { public void doSomething(); } class AService extends BaseService { public void doSomething(){ // Do something... } } class BService extends BaseService { ...
0 votes
0 answers
101 views

C# Web API Requests and multipart forms with json and files and not buffering the filestream in memory

I'm looking for some C# web API architecture advise on how best to minimize my memory when doing a "multipart/form-data" request which consists of a json payload with a single file upload. ...
  • 1
0 votes
0 answers
62 views

State Pattern: Changing object behavior based on more than one field and consistency between their values and state value

I'm Trying to learn about State Pattern. In most of State Pattern examples that I have seen, methods of class change their behavior based on just one field (I mean before applying State Pattern and I'...
1 vote
1 answer
113 views

Prevent users with multiple sessions using a single use voucher

I'm working on a .Net eCommerce site that allows users to use vouchers to get free products, discounts etc. The problem I have is that there have been instances of users, who have been issued single ...
0 votes
2 answers
577 views

Can a class be considered as a factory even though it only creates one concrete type of objects?

I have a simple class called Link that contains some properties, and use different classes for creating different types of links. My code looks like this: class Link { String reference, label, ...
0 votes
3 answers
120 views

What should be the optimal management of end user messages in N-tier architecture?

I'm curious about your thoughts on this subject that we have discussed with the people around me. Especially at the architectural stage, in which layer is the most optimal and efficient way to use the ...
  • 13
43 votes
13 answers
7k views

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Consider your have an enumeration that looks like this: enum ProcessingType { CONFABULATION, RETICULATION, SPLICING; } And you have a web-service that looks like this: class WebService { ...
  • 960
0 votes
0 answers
39 views

Query for each doucment or include IDs in document itself and query for all documents with ID?

I am working on a project where there will be different kinds of accounts that use Auth0 for auth and authz. I want to have it so that an account will query my backend to get back documents that ...
  • 161
3 votes
2 answers
267 views

How to structure many complex conditionals on a class

I have a class (as a protobuf) OrderChange, that represents when an order (imagine Amazon.com) changes: message OrderChange { Order old_order = 1; Order new_order = 2; } message Order { ...
  • 159
0 votes
2 answers
189 views

Design for three classes with partially shared logic

I am looking for a suitable design which uses composition to allow three classes to share some logic. The problem I am solving is that I have to read 3 different json configuration files from my ...
  • 127
-1 votes
1 answer
93 views

Subclasses with same behaviour but different attributes for different inputs

Say I have two object types of the same interface MyObj (I am using python in this project so I will use the same for the explanation) class Foo(MyObj): a = [5, 10] class Bar(MyObj): a = [[1, ...
2 votes
2 answers
673 views

Is returning true or throwing an exception good or bad code practice?

I am focosing on learning better design and wondered if this code is good or an antipattern? The function validate return true if data is correct, else it will throw an exception with a message to ...
  • 53
2 votes
2 answers
81 views

Modeling combination of two independent abstractions

I am building an app (.NET, but whatever) which is supposed to be able to send notifications to users. Each Notification can either be a Reminder or a Newsletter, and I'll possibly add more types in ...
  • 159
-1 votes
1 answer
225 views

Source of "... against the interface, not the implementation"

For a paper I am writing, I need to find the origin of the following two phrases: Code against the interface, not the implementation and Test the interface, not the implementation (Note: the ...
  • 31.5k
0 votes
2 answers
60 views

Getters and (static) processor vs multiple processor wrappers

I've got a class which stores two data series like so. I need to do some complicated processing on each of these arrays, but for now we'll just get the average of each data series. I could either do ...
1 vote
4 answers
422 views

How to convince colleagues to stop writing static classes [closed]

I recently joined a new company. After working on some projects I noticed a pattern. Every project contains a lot of static classes. A lot of static Helper classes. ApiHelper JsonHelper UmbracoHelper ...
0 votes
1 answer
159 views

Inject configuration files into the injector is it an antipattern?

I'm trying to design a system that inject configuration of each component into each class. project structure: |features --|component-a component-a.service.js component-a.config....
  • 109
-3 votes
1 answer
292 views

How to implement state machine to card games such as poker or russian poker?

These are my class designs: I also have Controllers where I can create table, create users add users to table, deal hands simulate user bets using PostMan (Above classes are game engine classes, I ...
  • 11
1 vote
3 answers
261 views

How to use abstract factory on interacting widgets

Context In many GUI frameworks, it is very common that widgets are placed in a container to arrange them visually in a window. For example, in Gtkmm, a window with a label and a button (side by side) ...

1 2
3
4 5
86