Questions tagged [design-patterns]

For questions requesting extra attention to be paid to the usage of design patterns in the code.

Filter by
Sorted by
Tagged with
4 votes
1 answer
206 views

Abstract base class for binary serialization

Ensuring that some logic is always being run before the user's overriding methods. I'm writing a library and I have some abstract classes that can be binary serialized (and users can subclass them and ...
  • 409
2 votes
1 answer
56 views

Composite and proxy pattern for multiclassing

A Multiclass is a CharacterClass that decided to add new CharacterClass types to combine with the original CharacterClass. These new CharacterClass types are ...
  • 1,319
1 vote
1 answer
73 views

Prototype design pattern

As a practice and self-development exercise I have decided to implement design patterns in C#. I am using polish cuisine as an example in my implementations. In this project I implemented Prototype ...
  • 169
1 vote
1 answer
68 views

Singleton design pattern

as a practice and selfdevelopment exercise I have decided to implement design patterns in C#. I am using polish cuisine as an example in my implementations. In this project I implemented Singleton ...
  • 169
3 votes
1 answer
68 views

Builder Pattern for factory creation of beings with different races

Races have many distinguishing physical characteristics. But apart from appearances, different races have other distinguishing characteristcs, all of I've decided to be built using the Builder ...
  • 1,319
-1 votes
1 answer
46 views

Replacing private helper methods with global functions in Python? [closed]

In Python there is no real notion of private access. It's merely suggested by social convention with _ prepended in method names. ...
4 votes
2 answers
427 views

Composite Pattern for putting on clothes

When putting on a piece of clothing, we need to check for any clothing that is already on the relevant body parts(s). The possible plural means that we should use the Composite Pattern for the body ...
  • 1,319
1 vote
0 answers
38 views

Frontend to handle course planning and administration [closed]

I read up on and dived into the Repository pattern for a project I am working on. I have understood that the repository abstracts the actual access to any form of storage for my data model. What I was ...
1 vote
1 answer
52 views

Chain of Responsibility pattern for updating coordinates of moving objects

PrimaryCoordinates are the coordinates in meters. SecondaryCoordinates are the coordinates in decimeters, with the origin ...
  • 1,319
1 vote
0 answers
58 views

Check that inputs are valid dates

I have a method in a class that accepts either a datetime or string parameter. It is shown in the last code block (I didn't include the class). A little background is that I am defining a wrapper ...
1 vote
2 answers
76 views

How to transform the CompletableFuture response

Context: I have a client app which consumes an API. I want to call this API is async way (using java.net.http.HttpClient) and once I receive this data then I want ...
  • 11
1 vote
1 answer
66 views

Build a message string depending on the type of signature of an invoice

The following method was meant to build a message depending on the type of signature of an invoice. It contains some if-else statements and code duplication. The original method : ...
4 votes
2 answers
155 views

Automating the process of determining which boxes to load on each flight for freight company

I was given a test assignment for the interview of the company and below is the code that I shared with them. I developed it using .NET 6 (Core) Console application. Actual problem statement: Coding ...
4 votes
2 answers
110 views

Abstract Factory Implementation C#

I'm learning Factory pattern and I've implemented this simple example of an abstract factory. I've followed this video a little bit while writing this small example. Is there anything anti-pattern or ...
  • 141
3 votes
1 answer
58 views

I made a webpage that simulates sharks eating fish in the torrid world of Wa-tor

I've been self-studying HTML/CSS/JS. I read about Wa-tor. It's a population dynamics simulation which simulates fish and sharks breeding and predating. This seemed cool so I decided to implement it....
  • 33
0 votes
1 answer
93 views

Is this the correct way of implementing a builder pattern in C++?

Coming from a Javascript background, and just now getting into c++. Want to know if im doing the builder pattern correctly in C++, and also what could improve on ? PongObject.cpp ...
  • 251
1 vote
1 answer
133 views

Creating complex object step by step

Builder pattern separates object construction from its representation I have to generate username and password for the Account class. Since this operation is a bit ...
  • 631
0 votes
1 answer
37 views

Nodejs Module Pattern And Caching

The question is about nodejs module pattern code structure. My goal is to initialise the module at one time and export the module using module.export so that, it's ...
1 vote
0 answers
30 views

How do you decide if a function should return data directly (via return statement) or indirectly (e.g. updating a class property) or both? [closed]

I have some functions which update records in some database tables. When I run each function I want to know the number of records affected by each. I'm wondering what the most elegant way of returning ...
  • 119
2 votes
2 answers
193 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 ...
  • 410
4 votes
0 answers
85 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 ...
  • 238
4 votes
1 answer
256 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
50 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
154 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
76 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 ...
  • 127
2 votes
1 answer
60 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,683
2 votes
1 answer
74 views

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

I wrote an improvement from my previous graph class: Link ...
  • 1,683
1 vote
0 answers
134 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
55 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
134 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
157 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
65 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
114 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
100 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 ...
  • 21
1 vote
2 answers
66 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,319
1 vote
0 answers
68 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
1 vote
0 answers
243 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
32 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 ...
  • 751
0 votes
1 answer
99 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,319
0 votes
0 answers
142 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
86 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 ...
2 votes
1 answer
74 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 ...
  • 301
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
102 views

Decorator Pattern with member functions

Motivation: without SaveDecorator, we would have to write: ...
  • 1,319
3 votes
1 answer
77 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
228 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
337 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
47 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
126 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 ...
  • 365
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,319

1
2 3 4 5
29