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
4
votes
1answer
145 views

Applying functions to decorated objects

I have an interface Animal with a class that implements it, Cat. ...
5
votes
0answers
53 views

Java service to convert xls files to HTML

I have a service that converts an Excel spreadsheet file into HTML. It is working just fine, but it is quite a big method that doesn't follow any SOLID principles. Therefore I would like to improve it ...
1
vote
1answer
32 views

Transform Data from JSON and CSV to another JSON format

I have 2 files wholesaler_a.csv ...
2
votes
0answers
59 views

Visitor pattern, Extensible visitor for custom implementation

I'm writing my own expression tree system, just for fun, but I have a few doubts about my code. My goal here is to create an abstract layer of expressions, and allow different "languages" to ...
1
vote
1answer
64 views

Builiding a Model from Stored Procedures

After reading that Data Classes can be considered a code smell, I am shifting from a pattern with many data classes and a single manager class that handles all the instantiation of the classes, to a ...
0
votes
1answer
68 views
0
votes
1answer
41 views

django multiple if else refactor

I have a function with multiple if else statements that I'm trying to simplify in Django Is there a pattern or maybe a better modeling approach that I could use here? The idea behind is to have a ...
2
votes
4answers
99 views

statistics classes with number and object inputs

I want to create two classes that accept values and perform operations on them. However, one of them is accepting numerical values - RollingStatisticsNumbers; and the other objects - ...
2
votes
0answers
31 views

How do I create an “Environment Variable Setter”?

I have a NodeJS/Typescript project. In server.js, I want to set my environment variables from a .env file. To achieve this, I am ...
5
votes
1answer
79 views

Generic Visitor pattern library for polymorphic virtual class hierarchies

Inspired by this cppcon talk from Fedor Pikus about design patterns and some real-world need I implemented a library that allows the user to add a generic visitor pattern capabilities to class ...
3
votes
2answers
61 views

A Python decorator for an “observable property”, that notifies observers when the data is changed

I have classes that have some data, and whenever this data changes, it should notify observers of that data change. There also should be a method to add new observers. My first approach was to use a ...
2
votes
0answers
30 views

Python - preprocessing dataframes data in a class

Context I am building an algorithm that automatically assigns a planning to drivers. However there is a lot of pre-processing and reused outputs. I try to structure it in a maintainable way. Questions ...
0
votes
1answer
20 views

on using the strategy pattern to switch between database layers

I'd like to build an app in Flask that can switch between talking to a PostGresql and a Mongo DB. As I understand it, the Strategy Pattern is about being able to switch algorithms that are referred ...
1
vote
1answer
30 views

Avoiding verbose compositional class design

I've written some code which features Eric Elliot's javascript factory function mixin composition (https://medium.com/javascript-scene/javascript-factory-functions-with-es6-4d224591a8b1), but since ...
3
votes
1answer
51 views

Design pattern for creating similar but different classes

I have a main-class that takes a list of sources and returns two objects for each source; one with the required data and one analytics tool. The Analytics-class has ...
3
votes
1answer
63 views

Revised console-based quiz application

This question is a follow up to my previous question, link to the post can be found here. I really appreciate the reviewers especially @Edward's review. They highlighted great points which were ...
7
votes
4answers
340 views

Console-Based Quiz Application

I wanted to practice more object-oriented programming and decided to write a console based Quiz Application. In one of my previous question, a reviewer left some links on SOLID design pattern, I went ...
1
vote
0answers
27 views

How to put my functions outside a class to get organized, Design pattern [closed]

I'm using Symfony 4, I have a class named Fiche, it contains the attributes and by default the getters and setters functions of course. Inside this Class, I have created over than 107 others functions ...
6
votes
1answer
51 views

MessageHandler handles different message subtypes differently (can visitor pattern be applied?)

Introduction I'm working with Java 1.8. There is a lot of repetition in the MessageHandler class that I would like to remove but I'm having trouble implementing a ...
10
votes
1answer
244 views

Snake Game Object Oriented Approach

I just completed a snake game using object-oriented programming. The focus is on the class implementation. OVERVIEW Snake game works by moving the snake in order to eat fruits whilst escaping ...
1
vote
0answers
52 views

Is this a good pattern design for a Unity dispatcher for creating thread safe methods?

Well, my intention here is to allow users to execute Unity methods/properties in other threads by using this Dispatcher implementation: ...
4
votes
1answer
97 views

How to refactor Symfony 5 controller to comply with SOLID design principles

I am trying to create this API endpoint that will accept JSON payload and will calculate quote based on provided factors and their ratings. I have Entities that contain information about: ...
5
votes
2answers
90 views

Object Oriented Library Management System

Library management system is a object oriented program that takes care of the basic housekeeping of a library. This is the third part of a series. The first iteration of the project is found here and ...
0
votes
1answer
73 views

Learning factory design pattern [closed]

I'm making the very common example of Factory design pattern which creates a factory of cars and return an instance of a car. I found a example here https://refactoring.guru/design-patterns/factory-...
4
votes
2answers
322 views

web scraper for emails and links

I created a class to scrape URLS, parse and validate emails and get internal links. How can I achieve the SOLID principles in this class written in Javascript to make a web scraper? ...
3
votes
1answer
64 views

refactor python strategy pattern to use abstract base class

I came across this strategy pattern implementation https://github.com/jtortorelli/head-first-design-patterns-python/blob/master/src/python/chapter_1/adventure_game.py ...
4
votes
1answer
108 views

Modular Design Patterns in C

I have created a modular design pattern which provide a single interface that can be used create instances with swapable back-end components, however I'm not entirely satisfied with it. My practical ...
1
vote
1answer
53 views

Soduku Generator and Solver

This is my approach on creating a sudoku generator and solver with backtracking. Is right for sudoku generator to inherit from soduku solver? What is your general overview on the class structure, data ...
3
votes
1answer
81 views

Implement Factory pattern with multiple parameters and each parameters are interface

I am a little bit confused on Factory Method with multiple parameters in which all parameters can change from GUI by user as seen below picture. For each combobox item I have an interface and ...
2
votes
0answers
15 views

Pre setup script to get user metadata and check supported api's within the browser/device

Can this code be shortened or optimized, Written out this script to be used before node.js starts a few canvas elements and some vide streams. wondering if the initial checks can be shortend or ...
0
votes
0answers
9 views

Tree design in db with same child twice and value store

I have a non-cyclic tree like the below sample representation. It has nodes and edges connecting them. The tree has the possibility of the same node connected multiple times to one parent. Like in the ...
1
vote
0answers
38 views

Instantiation logic within a specific object vs factory object

I want to program file lines transformation in a game initialization context and I am asking about best OOP practice. I have a MockConfigFile that implements a <...
25
votes
1answer
2k views

A Pong Game using C++

I wrote a simple, 2-player Pong game for a Udacity Nanodegree in C++. The program has the following class structure (relatively new to UML so any tips on here would be very much welcome too): ...
2
votes
2answers
134 views

Reactor pattern in modern C++. Please comment on coding improvements to be done

The reactor possesses its own thread to wait for messages in an event loop. Users should be able to start or stop the reactor at any point. These two operations are not required to be thread-safe. ...
8
votes
1answer
329 views

Testing lower- and upper bound values in Python

Code functionality The following code tests whether the values that a user specifies for a lower bound and upper bound on two properties: The lower bound is smaller than the upper bound. The values ...
4
votes
3answers
161 views

Many DB queries and conditions [closed]

I don't know it is some design pattern for it or I can't do it in a different way the code looks like this: ...
2
votes
1answer
66 views

Defining a finite set of instances of a class to check against [closed]

I have a Type class that will have many instances. I get the instances from a web service. The Type class has a ...
2
votes
2answers
101 views

Loan application service based on user credit score

The following microservice is just handling loan application and response the result of the application is accepted or rejected. It is part of my assignment for an interview. The project description ...
8
votes
1answer
220 views

Making argument parsing more streamlined and readable than if-statements

I am working on an API wrapper for calls to a website. Each of several types of calls can take a large number of optional arguments, some of which contradict. In the interest of preventing the user ...
1
vote
1answer
64 views

Prototype Design Pattern C++

I have just started reading the GO4 book to learn the OOD concepts. In order to practice the Prototype pattern, I implemented a small example (the idea for colored shapes was taken from "...
2
votes
1answer
62 views

Implement Strategy pattern for 1. Print Report. 2. Movie type [closed]

I need to know whether I have implemented Strategy pattern correctly for below 3 classes provided to me for 2 tasks.1) Report Generation 2) Movie Type. Below 3 classes were provided to me Rental.java ...
3
votes
1answer
52 views

Typescript design pattern for rendering different objects with similarities

It's a web project. The code is working. The question is a design pattern question to write code that's more elegant, you know. I've created a Codepen of this question. I created a ...
0
votes
0answers
23 views

Discord bot file requirement and object instantiation d20pfsrd follow-up

I have written a series of parsers for a discord bot that each reside in classes in their own files. Each parser class has 3 functions, 2 of them are for generating the response to the discord message ...
4
votes
1answer
207 views

Representation of data record for an employee (generic method vs design pattern)

preface: I have a part of my code that is repeated more than once and I want to create a generic method or follow a design pattern to make the code cleaner. What I'm trying to achieve is: I have a ...
3
votes
2answers
143 views

C# One type to represent multiple types (including generics)

Our monolithic WinForm application is getting a face lift. One current challenge that we are restructuring how we setup events. I rolled my own event manager class to handle the subscriptions and ...
2
votes
0answers
52 views

Structuring Service and DAO Layers in Go

I am having a bit of difficulty in designing my Go code. I'll try to demonstrate things with a very simple example of adding a new user to the database. My Handler is only doing one thing: Calling a ...
5
votes
1answer
50 views

Instantiate multiple classes in another class, invoke method from multiple classes

The goal here is to pull all alerts from a single iterable: obj = Alerts(db, args) for alert in obj.alerts() pass Now, I need to add a few more sources and I'm ...
3
votes
0answers
71 views

Providing a connection pool

I need some opinions about method naming and single responsibility principle. First of all, let's talk about method naming. The class below was created to provide a connection pool and whenever a pool ...
1
vote
0answers
58 views

Self Running iterable state machine with Enums in Java

During development I needed to design a state machine with decision which runs to completion and performs state transition without the need to wait for events. So i come up with the following ...
4
votes
0answers
56 views

JS Stopwatch - Is this a good way to implement the observer pattern?

I'm learning oop and also trying to learn and implement some design patterns. This question is a follow up of Stopwatch interface OOP (Vanilla JS) The app is available in https://nacho-p5.github.io/ ...

1
2 3 4 5
27