Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [design-patterns]

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

1
vote
1answer
33 views

View for logging telephone calls

As part of a web-based claims system I have created, there is a view for logging telephone calls. If a call is incoming, the claims handler asks the caller a series of data protection questions to ...
3
votes
1answer
68 views

Implementation of Strategy Pattern (photo gallery example) [closed]

I'm learning design patterns and I thought that it would be a good idea to make my examples of each pattern. This is my example of the Strategy Pattern. Can you tell me is it good and what to improve? ...
2
votes
1answer
109 views

Generic UnitOfWork

I am trying to create a Repository & UnitOfWork for Data Access Layer. In my current implementation I have to modify my UnitOfWork everytime I create a new repository. I would like to avoid that ...
5
votes
2answers
147 views

SOLID principles breaking in interview task (file parser)

Originally asked on Stack Overflow I recently had an interview where interviewers asked me to Rewrite following code with SOLID principles. Add a new file handler (...
1
vote
0answers
52 views

Proper separation of behaviour and data structure when the data structure is complex

The code in its full glory, complete with unit tests is here (and some discussion of the issue). I am struggling with how the principle of separating data structures and behaviour applies here. This ...
1
vote
1answer
112 views

Command pattern for simple text editor

I was asked to code a TextPad with following functionality: display() – to display the entire content display(n, m) – to ...
0
votes
0answers
32 views

ROR - Point of Sale (POS)

I've the following scenario: the user clicks the "Sales" button which redirects to the creation view of the Shopping Cart. Then, the user enters the EAN code and the Quantity, presses "Add" and the ...
0
votes
2answers
82 views

Binary Search Tree implementation with unique pointers

I have implemented a binary search tree using templates and unique_ptr in C++ 11. At present, only insertion and deletion are implemented. Please provide your feedback for improvements. ...
1
vote
0answers
57 views

Further dive into filtering using IPredicate

Preface This is a follow up to my previous post from not long time ago about containers and filtering. This post can be found here. Now, I will attempt to expand what I have learnt from the answer ...
6
votes
1answer
109 views

Class containers, filtering and coding practices

Context Usually, when I have to deal with a collection of items (especially objects) I tent to create a container class for that collection (wrapper?). What I mean by that is: when I have to handle ...
-2
votes
1answer
23 views

List of abstract object that requires instanceof and casting [closed]

I Have a class which calls a method, that will convert an excel file, and each sheet will be a DTO, and returns a list containing those DTOs ...
1
vote
0answers
21 views

run different validation strategy based on condition

I need to execute different validators depending for different countries ($country_id), each validator should return error message variable in case of failure. One validator (CommonValidator) is ...
0
votes
0answers
36 views

Auto-registering CRTP Factory

I'm trying to write a policy based auto-registering class using the Curiously Recurring Template Pattern. I decided as design choice to not using registering macro. Factory Class ...
8
votes
3answers
993 views

Binary Search Tree implementation using smart pointers

I have implemented below code for binary search tree implementation using shared pointer. At present, I have considered only integers. It supports insertion and deletion of values. Also, a print ...
4
votes
3answers
504 views

Pass IEnumerable<T> as an argument of method and repository pattern

I've seen tutorials of Unit Testing and I've never seen that IEnumerable<T> used as an argument of method. All authors use ...
1
vote
1answer
43 views

Simple local cache that checks by date else get from db

I'm looking for feedback on how this can be improved, basically what I'm trying to do is check if the cache has the object else check from the database. I have list of ids, then I separate them based ...
1
vote
0answers
66 views

Image capture client - multi-threading + sharing data between services

I'm working on a small side project at the moment - like a homemade CCTV system. This part is my Python Capture Client - it uses OpenCV to capture frames from a connected webcam and sends the frames ...
0
votes
1answer
74 views

User class: getting user data, logging in, secure CSRF session handling, logging out

In reference to my previous code: User class: getting user data, logging in, secure CSRF session handling I re-wrote my SystemUser class, without the DI container (for now), I'm still trying to ...
0
votes
0answers
20 views

Go interface design for a cluster provisioner application

I'm fairly new to Go and working on an application to create VMs in a some cloud provider. I'm trying to design interfaces and I'd love some reviews. The application creates a cluster (group of VMs ...
2
votes
1answer
103 views

User class: getting user data, logging in, secure CSRF session handling

I wrote this class a few months ago and noticed from a few examples that it's better to break down these classes and separate them. I am not so sure what is the proper way to break it into parts. It ...
4
votes
1answer
85 views

Sourcing data format from multiple different structures

Problem I want to read in the data to dictionary person = { 'name': 'John Doe', 'email': 'johndoe@email.com', 'age': 50, 'connected': False } ...
1
vote
2answers
41 views

Map a set of types to unique IDs and runtime reinterpret back from ID and pointer in C++17

I wanted to create a relatively universal way of serialising an object, by doing a memcpy and generating a unique type ID. Stored together they can be used, for ...
2
votes
1answer
66 views

C++ smart pointers and the Service Locator (anti-?)pattern

So I'm working on a game framework and one of the things I need are access to stateful "services" that can be accessed from all over. I was initially going to use the Singleton pattern but decided to ...
4
votes
1answer
207 views

Defer pattern for constructors in C++

In some specific scenarios, I want to run code after the constructor for a class has run (namely: access std::enable_shared_from_this::shared_from_this()). To solve this without introducing an error ...
5
votes
0answers
73 views

Prototype GameManager for game written in Unity

I am self taught, so I'm consistently seeking ways to code better, and more efficiently. If anyone has the time, please advise me on what can be done better with explanations as to why the old method ...
0
votes
1answer
51 views

Tile and grid abstraction

This question is a small subset of the problem I am trying to solve. I am trying to learn to break problems into better abstractions. The original problem I am trying to solve is: Write a JS ...
2
votes
1answer
49 views

Use of inheritance using two Ruby libraries

Currently I'm working on parsing data from a form service into a pdf form. I created 2 classes one inheriting from the other one. However, I see that the classes I created are growing in lines of ...
4
votes
1answer
134 views

Collections management with many derived elements

I've been told few days ago that using is is a code smell and anti-pattern. I used it in an game to filter some elements of a collection (the inventory of the ...
2
votes
1answer
60 views

Squeezing decorators into functional extensions

When you try to use several decorators it can get ugly pretty quickly and you'll end up with: ...
1
vote
2answers
243 views

Using decorator and strategy pattern for dynamically generating SQL queries

This is a link to my application that actually runs on the design specified in the image. The idea behind the image is that the SubjectInfoViewer behaves as the ...
5
votes
3answers
463 views

Length units converter

I am creating a very small application to demonstrate solid principles and also a brief implementation of a builder pattern, does anyone have any feedback as to how this could be improved or how it ...
3
votes
0answers
69 views

Bridge-Pattern or Entity-Component-System

I want to learn how/when/why to use the GoF Design Patterns. These last days are dedicated to the Bridge Pattern, which means: Decouple an abstraction from its implementation so that the two can ...
14
votes
3answers
400 views

Building unusual IComparer<T> from expressions

I've needed a couple of very special comparers recenty and didn't want to implement each one of them every time so I created a builder and a couple of supporting classes that do that for me. Example ...
2
votes
0answers
51 views

Builder Design Pattern To Store User Information

I am new to building with design patterns. I have been working on implementing the builder design pattern in PHP. I just want to make sure I am doing it correctly. I have been following along with ...
5
votes
1answer
87 views

Service for generating faked objects

I'm using the Bogus library to mock up some data for testing. This is my main method demonstrating how the faking service should be used: ...
2
votes
0answers
114 views

Timer application in MVP

I create simple Android timer application and I try to use MVP design pattern. I read some tutorials and after that I started writing code. My code is working correctly and as intended. There is ...
1
vote
1answer
401 views

Flip coin Game in an Object oriented way

I started out creating a simple game in an Object Oriented way to practice. The rules are pretty simple There are two players You let one player choose if they want Heads or Tails. You assign the ...
0
votes
1answer
61 views

Invocable callout(Post) from processbuilder

I am relatively new in making (invocable)callouts. My main concern is if I should be using smaller parts for example for the body and using a query only once in this case. Any suggestions would be ...
4
votes
3answers
241 views

Finite State Machine in C++

I made a state machine. You can press 0 and 1 to switch between the hypothetical menu and playing state. I hope you can help me improve it further. StateManager.h ...
2
votes
0answers
50 views

Best approach to parse data from multiple APIs to Entities in PHP

I built an application that extracts and updates data from multiple ecommerces websites. Each eCommerce is either built using platforms/frameworks such as Shopify, Prestashop or WooCommerce. This ...
5
votes
3answers
514 views

Apply discount changes with Strategy pattern

I am implementing strategy pattern. I have defined a strategy as interfaces and concrete classes to implement the strategy. Based on user selection/configuration, the algorithm to apply the discount ...
2
votes
1answer
381 views

C++ - Object Oriented File System Design using Composite Design Pattern

I am trying to come up with a good File System Design using C++ / OOP. This is being done to gain an understanding of System Design and Design Patterns. I have some basic functionality, like reading ...
2
votes
0answers
42 views

Method for creating and traversing a BST while also getting its depth and width

This is a class for creating and traversing a BST while also getting its depth and width. I feel like this can be factored down into something more elegant and shorter I also feel like the overall ...
3
votes
2answers
133 views

Replace a #define/template “Variable Wrapper” system with a pure template/OOP solution

I have an inherited code base that I am looking to improve. Below is a "variable wrapper" template class and #defines that i would like to replace with a template only solution, or redesign ...
2
votes
1answer
393 views

C++ multithread pool class

I have addressed the critique for this post and resubmitted it for iterative review; C++20 multithread pool class. This is an iteration from a prior post; C++ thread pool class. Class for creating ...
2
votes
3answers
222 views

State Pattern for traffic lights

I tried to implement a traffic light system using state pattern, please comment on the OOP/design pattern use. ...
-3
votes
1answer
77 views

Application for writing checks

I am writing an application which has lot of checks. Most of the logic is based on conditions. How can make such code comply with SOLID principles? I cannot give the code of my application here hence ...
1
vote
2answers
130 views

Design Pattern to Add, Edit and Delete Records

This code does Add, Edit and Delete a database record for the Category table. Separate Service classes are implemented to handle these operations which are called via the Web API Endpoints (...
1
vote
0answers
53 views

Call center escalation excercise, using Chain of Responsibility pattern

This is a coding interview I found online, to be solved within 30 minutes: Design an OOP concept for an application where employee can dispatch their incoming phone call according to their ...