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
2 answers
58 views

Requests and handling requests

For this task, I don't think that the Observer Pattern can be used in its classic form. Those who have received the requests and those who choose to accept the request are not the same group. Those ...
user avatar
  • 1,089
1 vote
0 answers
41 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
user avatar
1 vote
0 answers
123 views

Inheriting from a JSON converter class with schema definition through constructor

I wanted to convert C++ data structures to JSON with little code. More specifically, I wanted to convert C++ data structures to nlohmann JSON representation. Project context: The goal is to use this ...
user avatar
0 votes
0 answers
24 views

Two different JavaScript implementations of the observer pattern using class inheritance and concatenative inheritance

To practice design patterns and JavaScript, I'm implementing the observer pattern in two different ways: One implementation using class inheritance And another implementation using concatenative ...
user avatar
  • 729
0 votes
1 answer
91 views

Simultanous states in a state machine

In Dungeons and Dragons, we have many spells, e.g. the Charm spell to get anyone to do what you want, the Web spell to entangle someone, the Invisibility spell to make yourself invisible (but once you ...
user avatar
  • 1,089
0 votes
0 answers
78 views

Implementation of Strategy Pattern for Task Scheduler

I need to implement a feature that schedules notifications to a user to which a Task has been assigned. The schedule could be one-time or on a ...
user avatar
  • 101
2 votes
0 answers
69 views

Is this a valid implementation of Memento Pattern in C#?

I've been studying design patterns from GOF for a few weeks, especially in C#, and I'm struggling with Memento Pattern. I know there are a lot of C# implementations on the web, but I came up with my ...
user avatar
0 votes
1 answer
35 views

Adapter pattern apply with JsonObject

The purpose of the code is to apply adapter pattern to put an extra feature for searching through json object. I hate deep nested json object because it makes my code look messy when access through ...
user avatar
  • 271
2 votes
1 answer
52 views

c++ general feedback on a custom performance oriented array

Introduction I have written a first iteration of a 3d rendering-program utilizing openGL and c++ and i am looking to get some of my code reviewed. As i am self-taught and have never received any input ...
user avatar
0 votes
1 answer
54 views

Decorator Pattern with member functions

Motivation: without SaveDecorator, we would have to write: ...
user avatar
  • 1,089
3 votes
1 answer
67 views

Number partitioning: how to allow both 'light' and 'heavy' output?

I am working on a library for algorithms for multiway number partitioning. One challenge I face is that some users need the entire partition, while other users need only the sums of the parts. For ...
user avatar
0 votes
0 answers
70 views

Is using State Pattern with nullptr states by default a good idea?

The following code uses a State Pattern with the states as pointers in a tuple instead of objects because many such states would not apply to people (e.g. HasSecretCrushState). So the pointers are ...
user avatar
  • 1,089
1 vote
1 answer
94 views

Another Vending Machine implementing State Pattern

I previously asked for a review for a Vending Machine implementing State Pattern in this linked post. And received an answer from @radarbob. The code below is my revised attempt based on some of @...
user avatar
5 votes
1 answer
160 views

Vending Machine implementing State Pattern

I was asked to implement a Vending Machine in a recent interview coding challenge. My attempt at a solution is based on the state pattern. I would like to get some code reviews on this bearing in mind ...
user avatar
3 votes
1 answer
36 views

Exporting a merged dataset from multiple source to a downloadable link

I'm working on a use case in hobby project where I am merging data from an external data source with an internal one and exporting that to a downloadable file The use case is exposed in an ...
user avatar
  • 153
4 votes
1 answer
96 views

Command design pattern for RPG prototype

I'm writing an assistant for the tabletop RPG Pathfinder in Java. I already have a few building blocks and decided to make a small side-project to play around the Command pattern. I know that there ...
user avatar
  • 310
2 votes
1 answer
57 views

Pattern for people relations

Consider the following code. I'm trying to figure out a proper pattern and this is the best I can think of so far. The strange part is the transition from storing "people seen" to "...
user avatar
  • 1,089
1 vote
1 answer
44 views

Handling resource authorization in a service

Problem: My application is built upon clean architecture. I want to create a new instance of a class in my lower layer, but the class itself resides in an upper layer. The upper layer can depend on ...
user avatar
1 vote
1 answer
69 views

Memento Pattern between sister classes

The following is my usage of the Memento Pattern when one class uses the copy constructor of a sister class (a separate derived class of the base class) and wishes to revert to the previous class. ...
user avatar
  • 1,089
4 votes
3 answers
112 views

Observer Design Pattern in C++ to model magazine subscriptions

My attempt at a observer design pattern (I know using namespace std isn't good). I'm very new to design patterns. Everything is inline with class definition. Please tell me if I'm doing anything wrong ...
user avatar
2 votes
2 answers
108 views

Finding and changing filenames of different media files (photos, videos)

My tool should eventually change all media files' names to one qualified format yyyymmdd_hhmmss [optional desc].xxx: If it's an image, the date is taken from "Date Taken" property of the ...
user avatar
  • 251
-4 votes
2 answers
131 views

How to design planet class so that it is open for changes? [closed]

The task is to model a Solar system using OOP. The planets are orbiting and its needs to find distances between planets. My approach is something like this. ...
user avatar
0 votes
1 answer
51 views

Image scraper using Dependecy Injection in Rust with generics

I'm writing a scraper that downloads images from a given subreddit. I'm new to Rust, and in the majority of my previous projects I was using C++ or Java, where it's easy to do Dependency Injection. I ...
user avatar
2 votes
2 answers
108 views

Python - Temperature - descriptors with conversion

So I'm trying to understand the concept of descriptors and gathered some code together and made an exampel out of different sources. Like the offical documentation and StackOverflow answers. I'd hope ...
user avatar
3 votes
1 answer
140 views

Abstract Factory in C++

I have tried my hand at the abstract factory pattern in C++: ...
user avatar
  • 483
1 vote
0 answers
37 views

Scraping online store and writing to database

I'm making a project that will scrape some online store for an item, gets the data and stores it in a remote database that I have, and also able to read the database and display the data on a ...
user avatar
  • 63
2 votes
2 answers
80 views

Nop class which can get optimized away

I designed a class for debug builds which does not incur any overhead in release mode. A usecase is for example: I have a function and I want to count how often it is called. For this I could write ...
user avatar
  • 225
1 vote
3 answers
167 views

Abstract Factory Pattern Implementation

I implemented the Abstract Factory design pattern as follows. Concrete Implementation ...
user avatar
  • 165
1 vote
2 answers
101 views

Using Factory Design Pattern in Rest Controller of Spring

I used factory design pattern to identify the service according to the enum that comes from the api uri as request param. Everything seems okay according to me but cannot be sure if I used it right. <...
user avatar
0 votes
0 answers
32 views

Should I replace this request queue?

I just found myself hacking around the limitations of a backend that aborts highly concurrent transactions by queueing the requests using Solution A. I don't like this solution very much, and have a ...
user avatar
0 votes
0 answers
29 views

Update database records on data model change

Worker.php ...
user avatar
  • 101
-1 votes
1 answer
51 views

Using Factory Design Pattern in Spring [closed]

I organized the factory design pattern but I'm not sure if I used it right or wrong. Here's my data model; ...
user avatar
1 vote
0 answers
84 views

.NET Repository Pattern

I'm currently in the process of defining some framework, one of the first things that I thought I could start with was defining some repository pattern/layer. I generally wanted some input on it, ...
user avatar
0 votes
0 answers
132 views

Object Oriented Routing using Python's FastAPI

I created a BaseRoute class route handling. The BaseRoute class takes the following parameters: ...
user avatar
5 votes
1 answer
119 views

Design a pattern using python

I want to print the below pattern * * * * * * * * * * * * * * * My logic written ...
user avatar
  • 53
2 votes
1 answer
115 views

Using fluent builder pattern for generating pdf

I'm testing to use a fluent builder pattern for generating a pdf file using AbcPDF. I've looked at several methods of accomplishing this and I'd be very glad to get some input on what I've written so ...
user avatar
2 votes
0 answers
104 views

Undo/Redo implementation using Memento pattern Javascript

Relatively new to the Design patterns, Generally my works are writing function for the needs. But now i need to implement a undo redo functionality, so i just read about the different patterns which i ...
user avatar
1 vote
0 answers
41 views

Alert system for game or simulator

I am creating an alert system for a game/sim in C# that keeps track of negative actions performed by the user during a training exercise. There are preconfigured alerts that have data, such as UI text ...
user avatar
2 votes
1 answer
66 views

A proxy class as a generic replacement for getters and setters v2

Have you ever written proxy objects, instead of using a setter and a getter method? In that case, I'm interested in your opinion on the following design for a templated proxy. This is a second version,...
user avatar
  • 1,925
4 votes
0 answers
96 views

Sudoku sequence solver for non-standard constraints

This script is designed to help solve sequences in Sudoku puzzles with variant constraints (ex: Thermometer, Renban, etc.). Summary The user specifies the constraints they want applied as well as the ...
user avatar
0 votes
0 answers
32 views

Java database connection and DAO implementation feedback

First things first, I made a DatabaseConnection-class which connects to the database like so: ...
user avatar
  • 87
3 votes
0 answers
77 views

Arcade Stacker Game - Core Logic

This is my first post here, so I apologize if anything is incorrect. I have created an endless arcade stacker game (like the stacker games at the arcade, but when you hit the top the grid resets and ...
user avatar
  • 131
0 votes
0 answers
14 views

PHP Class(es) for setting up DB adaptor

Not sure if I have gone over board with this or if I have even approached it correctly. Basic I wanted to created classes which fulfilled the following: Single class that can be used to create a ...
user avatar
0 votes
3 answers
74 views

What is the elegant way to merge collection of entities with a duplicate field?

I have the following entity, I am getting it in response of REST API. class Account { private String ownerId; private List<String> coOwners; } REST ...
user avatar
1 vote
1 answer
113 views

Generic decorator inspired by functional programming

I made a generic decorator in C++20 with concept for specialization. The idea is to be able to define only one function in the decorator to decorate all functions in a class. You may try it (it's a ...
user avatar
0 votes
1 answer
53 views

Refactor typescript long switch case that run different code in according to property value

I have a typescript function that executes an array of actions on a given string value. This is the code: ...
user avatar
  • 183
0 votes
0 answers
53 views

Two sets of scripts for a Katamari Damacy-style game

I would like some feedback on trying to implement SOLID principles to my Katamari Damacy-style game, I have provided below the 'original' script which accomplished a variety of tasks, and then the '...
user avatar
  • 1
0 votes
1 answer
30 views

Function pattern for running DB queries using pool or transaction

Take the following INSERT query. Using knex (JS) just for abstractions ...
user avatar
0 votes
0 answers
211 views

React Typescript Project Using Traditional OOP Patterns

I'm writing an app meant to have similar functionality to LucidChart - drawing shapes/diagrams. I'm using React with Typescript (Create React App) and am trying to follow OOP/polymorphic patterns I've ...
user avatar
  • 131
1 vote
0 answers
147 views

VBA OOP design patterns: factory, constructor, returned interface

While working on my demo database manager app, I have coded a previously presented Storage Library. The structure of the library's code and employed design patterns partially follow that of the Secure ...
user avatar
  • 375

1
2 3 4 5
29