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

Is there a way to structurize this code by using Strategy, Command or other pattern?

So I have a SceneManager class (code shown below) that I think should contain my "business logic" for loading scenes in some way that I want using ...
  • 131
2 votes
2 answers
178 views

Generic observable type

I am writing an observer design pattern that is not too complex but I still feel there's a lot for me to learn about C++ be it little details (especially coming from C). A couple of observations: I ...
  • 362
3 votes
0 answers
66 views

Securely generate Token for authentication

In my experience i had the need that some application (both desktop and web) can excange data to authenticate users (even if the data for authenticating users are not reacheable form desktop ...
  • 228
4 votes
1 answer
96 views

Java 2 Player Object Oriented CLI Chess Game

I just finished implementing a Java 2 player CLI chess game, it involves player putting in commands (i.e "move e2 e4" to move or "attack d1 d5" to capture.). I am trying to follow ...
  • 61
0 votes
0 answers
35 views

"Select dropdown" with state abstracted in reducer

I have created a Select Dropdown component with its state abstracted in the reducer. I am just updating this collective state using reducer actions and handling the side effects via ...
2 votes
0 answers
117 views

Is MVC an overkill for a chess CLI game?

I am working on a CLI chess game that only involves 2 human players, I decided to make it follow the MVC architecture to ensure separation of concern and to make the possibility of a GUI/web ...
  • 61
1 vote
1 answer
67 views

Code to determine move position in a hex grid when the user moves the stick on the gamepad

I have code that is responsible for determining move position in a hex grid when the user moves the stick on the gamepad. cameraAdjustedMovement is a ...
  • 131
2 votes
1 answer
55 views

C++ Refactored graph again, separated property maps from Graph type

This is yet another improvement from my graph class - Link Now property maps are no longer parts of Graph type, they are just stored in a member variable. This ...
  • 1,643
2 votes
1 answer
68 views

C++ Graph class with multiple property maps (edit)

I wrote an improvement from my previous graph class: Link ...
  • 1,643
1 vote
0 answers
125 views

Applying the Strategy pattern for payment methods

The strategy pattern is applied in the code below in the payment separation solution. Please evaluate if it is well done according to standards. I would be very grateful for suggestions. ...
0 votes
1 answer
43 views

PyGame Event Handling

I'm new to pygame and tried to write my own Event Manager because I couldn't find a solution I was satisfied with. So I wrote my own inspired by the observer pattern: ...
  • 821
3 votes
0 answers
106 views

Simple Java IoC container for dependency injection

I have come up with a quick and simple IoC container to enable minimal dependency injection support in one of my Java projects. The container supports services with: A transient lifetime, meaning, a ...
  • 173
1 vote
0 answers
46 views

Database Repository Class Using the Decorator Pattern

I have a base repository class that's using AWS DynamoDB, and I have also implemented a class named StocksRepository I'm wondering if I should create a StocksRepositoryWithLogs and ...
  • 46
1 vote
0 answers
87 views

Entity Component System (ECS) in Java

While trying to write a game engine, I came up with this ECS / Component Based Architecture for its physics and drawing logic. I want to get some feedback on its architecture. I am using reflection ...
  • 113
1 vote
1 answer
56 views

Design Pattern: Builder - BeautifulSoup directory navigation and scraping

I wrote a class on top of BeautifulSoup using the builder design pattern that allows for the navigation of the necp data directory. There are a couple navigation ...
1 vote
1 answer
71 views

Adapter pattern in C++ via Inheritance and Composition

Any suggestions on how the implementation of the C++ Adapter pattern could be improved here? Implemented via: Composition Inheritance What needed to be adapted was the ...
0 votes
0 answers
42 views

Resolver Factory Pattern for IoC in an Asp.Net 6 Web Server

I'm currently testing an experimental IoC pattern enabled by a factory implementation, currently implemented for use in an Asp.Net 6 web server. The pattern is intended to support lazy resolution of ...
  • 1
1 vote
2 answers
65 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 ...
  • 1,109
1 vote
0 answers
54 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
1 vote
0 answers
188 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 ...
0 votes
0 answers
30 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 ...
  • 729
0 votes
1 answer
97 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 ...
  • 1,109
0 votes
0 answers
114 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 ...
  • 101
2 votes
0 answers
81 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 ...
1 vote
1 answer
62 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 ...
  • 291
2 votes
1 answer
55 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 ...
0 votes
1 answer
79 views

Decorator Pattern with member functions

Motivation: without SaveDecorator, we would have to write: ...
  • 1,109
3 votes
1 answer
73 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 ...
1 vote
1 answer
159 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 @...
5 votes
1 answer
249 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 ...
4 votes
1 answer
45 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 ...
  • 173
4 votes
1 answer
112 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 ...
  • 310
2 votes
1 answer
59 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 "...
  • 1,109
1 vote
1 answer
50 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 ...
1 vote
1 answer
82 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. ...
  • 1,109
4 votes
3 answers
135 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 ...
2 votes
2 answers
115 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 ...
  • 263
-4 votes
2 answers
178 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. ...
0 votes
1 answer
61 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 ...
  • 103
2 votes
2 answers
124 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 ...
3 votes
1 answer
214 views

Abstract Factory in C++

I have tried my hand at the abstract factory pattern in C++: ...
  • 483
1 vote
0 answers
42 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 ...
  • 63
2 votes
2 answers
85 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 ...
  • 225
1 vote
3 answers
178 views

Abstract Factory Pattern Implementation

I implemented the Abstract Factory design pattern as follows. Concrete Implementation ...
  • 165
1 vote
2 answers
286 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. <...
0 votes
0 answers
37 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 ...
-1 votes
1 answer
59 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; ...
1 vote
0 answers
94 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, ...
0 votes
0 answers
199 views

Object Oriented Routing using Python's FastAPI

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

Design a pattern using python

I want to print the below pattern * * * * * * * * * * * * * * * My logic written ...
  • 53

1
2 3 4 5
29