Stack Exchange Network

Stack Exchange network consists of 174 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

Questions tagged [design-patterns]

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

8
votes
3answers
788 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
485 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
35 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
64 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
67 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
18 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
90 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
82 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
37 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
60 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
166 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
61 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
38 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 ...
1
vote
0answers
33 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
118 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 ...
1
vote
0answers
38 views

ServiceLocator<T> with internal set [closed]

I was looking for a statically typed way of implementing a service locator and started by reading this series of posts. I then had an illumination. How about a static templated class with a single ...
2
votes
1answer
56 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
206 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
437 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
68 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 ...
13
votes
3answers
395 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
45 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
85 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
70 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
269 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
58 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
130 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
48 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
501 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
269 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
132 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
381 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
191 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
75 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
121 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
43 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 ...
1
vote
1answer
66 views

Lazy prime counting function [closed]

I have written a simple snippet of code that implements a function that returns a list of primes up to a certain integer n. Assuming that this function could be ...
2
votes
0answers
136 views

Simple bank OOP structure in PHP

I don't have much experience using either OOP or PHP since this is probably my first thing ever written in this language. I've had some exposure to OOP but I'm not used to writing programs that way. I ...
1
vote
2answers
61 views

Validation in BLL, many ifs - Suggestions how to refactor what I think looks smelly

We have an MVC application, which performs actions on a referral. We are added the business logic, to ensure that we can't perform invalid actions on the referral due to it not being in the correct ...
3
votes
0answers
54 views

News reading application version 2

following the answer I got from t3chb0t last time News-reading application using the Observer pattern and also following the example here https://msdn.microsoft.com/en-us/library/dd990377(v=vs.110)....
3
votes
0answers
759 views

Structure and Implementation of Generic Repository and Unit of Work patterns with Dapper and SqlTransactions

I am attempting to update some legacy code that I work with, but my knowledge of data access is limited to a basic use of Entity Framework and simple Dapper. After some research, I have a loose ...
-1
votes
1answer
108 views

PHP OOP registration with User class and singleton Database class [closed]

I created registration system with PHP. I have User class that will handle all the input and insert the user input into database, and i created Database class with Singleton pattern that will connect ...
4
votes
4answers
502 views

Initialized Array Template Class (C++)

The problem We want to use a very large array for some computations. When created, all the elements of this array have to be initialized to some value. We'll only use a few values from the array1,...
4
votes
1answer
204 views

Supermarket app using OOP

I am going in a circle over and over trying to write a "supermarket" application using OOP. The app should be useful for the employees of a supermarket. The app reads data from a CSV file which looks ...
0
votes
1answer
37 views

Convert automatically into a centralized bean for multiple domain objects

I am creating a project which will respond to collect multiple bean object, save it to the database and return the status of the transaction. There can be multiple objects that can be sent from the ...
0
votes
1answer
615 views

Object oriented design of chess game [closed]

I was trying to design a chess game in Java. I have just started learning design patterns and am not sure if my approach here is right. Could you please suggest ways to better this design ? Below is ...
1
vote
0answers
52 views

Design code to compute technical indicators

I have a table with OHLCV values stored per symbol and I am trying to compute various technical indicators for the same. I am a newbie to Python and this type of application in general. There are 2 ...
4
votes
1answer
289 views

PHP Application layers

I'm dealing with design layers of an application. Basically what I've so far are: Business Architecture: Client-Server Techonologies: PHP+MySQL, HTML5, JS, 3rd parties APIs My app Data Sources: ...
1
vote
0answers
37 views

design pattern for iteration php [closed]

I have this class where I can perform two loops on the same associative array, is there a design pattern that would accomplish this but with only one loop? I was thinking it would be ...