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
5
votes
1answer
36 views

Pin and Password Generator JAVA

I am reaching my one year on programming and decided to create a simple pin and password program to better help me understand arrays. As far as coding standards, best practices, and functionality what ...
-2
votes
0answers
36 views

Uploading image with Qiniu [closed]

This is my JavaScript code. This is a common component used for image upload with Qiniu plugin. And it's use vue and js. I think my code is not good but I don't know how to code better. I hope that ...
2
votes
1answer
40 views

Return payload in service layer

In my project I am using the ADR architecture, a branch of MVC. In my actions (Controllers) I handle only data that comes from the request. When there is a business rule that defines which status code ...
8
votes
2answers
351 views

C++, sort integers using knowledge of entire vector

I am solving the "Sort" problem on Kattis. Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea what ...
2
votes
1answer
49 views

React programming pattern

I create https://github.com/storenth/react-redux-todo and ask to review my Todo-react-app for programming pattern: dividing components into presentational components and container components. Here’s ...
1
vote
0answers
12 views

Refactoring Golang to avoid manual fields updating between similar structs and other redundant code

I'm using GraphQL and go-pg. I have many entities like these: ...
-1
votes
1answer
66 views

Is this implementation of factory design pattern in C#?

Here are my class library code which create credit card. ...
1
vote
0answers
43 views

Database connector in Python

I've been trying to build an ORM. I started with the connector layer, which is responsible for the database server connections and executes raw SQL as the code below shows. I have built the ...
3
votes
2answers
50 views

PHP Status class : pattern or anti-pattern

I want to abstract some code which does a bunch of checks and returns a boolean - since I am using the business logic in several places. But I also want to get back the reason why, if it was returned ...
0
votes
0answers
36 views

How to split and refactor a large function so it would do only one thing?

I am learning about clean and maintainable code. I heard that functions should be no more than 20 lines long (preferably 5 - 10 lines). I have come across this Bob Martin quote where he said: “The ...
6
votes
1answer
51 views

Design elevator to get user commands and execute request based on current elevator moving direction (UP/Down)

I have created an simple elevator design for 100 floors building with just one elevator. I have dependency between classes which I want to eliminate, any thoughts/suggestion to make it more better in-...
-3
votes
0answers
30 views

Best way to design a currency conversion service

We have a separate API that give us exchange rate for let's says USD to EUR on various API. To incorporate this into our express API, I was thinking of a express service that would contain a cache ...
1
vote
0answers
29 views

Switching article states using state pattern

The Article model supports a bunch of transitions. Only two are shown below: star()/unstar()....
1
vote
0answers
34 views

StateMachine Driven Workflow Design Feedback

Hi Im looking for feedback on design of my workflow - using state machine and swift combine. In my opinion, some aspects of the design violate single responsibility principle, cohesion, and overall ...
2
votes
0answers
42 views

Generic Graph Traverser

I have built this Generic Graph traverser, I have this implemented with DFS, I feel it will work equally fine with BFS too. What do you think of this implementation? I want help in reviewing the <...
1
vote
0answers
24 views

Designing a public facing Java interface for future extensibility (API evolution)

I develop an in-house Java framework. I provide an interface so that my end users can provide their own custom implementation (i.e. plugin/SPI). ...
1
vote
2answers
54 views

Scraping news articles from various pages

Scraping news articles from various web page is the main goal of this code. For starting all spiders(web crawlers) at the same time, I try to implement the facade design pattern. It works but I feel ...
2
votes
1answer
33 views

Download statements from Yahoo Finance

This is a Yahoo Finance wrapper to get income/balance statement for a stock ticker. What I have tried to do is make an abstract implementation so more features can be added easily in the future. The ...
3
votes
1answer
62 views

“Clean Architecture” design pattern with Node.JS and MongoDB

After some time poorly designing my web applications' backends (mixing database calls with the controller, etc.), I have decided to try the "Clean Architecture" approach. In this example I have a ...
4
votes
1answer
96 views

Resource management classes in C++ game

This is a part of simple sfml C++ game, but I think neither the library nor the language is that much crucial here. I am mainly worried about the design. I have a class template ...
1
vote
2answers
123 views

Trying (and failing) to implement the best conventions on OOP Swift

I'm making a MacOS app that will do some analysis on the user's calendar data. For now it only supports Apple's native calendar (EventKit), but I will later add ...
2
votes
3answers
83 views

Is it fine to typecast from one implementation type to another while using an object?

I've a simple code base with few 'weapon' concrete classes which implements different contracts in order to be used by its clients. My contracts: ...
1
vote
4answers
80 views

Java Fluent Wrapper [closed]

My gut tells me this is poor practice, so, I thought I would ask for some feedback. The goal here is to fake a fluent API design for any class without using reflection while keeping it as pretty as ...
1
vote
1answer
52 views

Reusing multiple switch cases and if-else statements [closed]

I am creating a 2D text-based Drawing Application which can draw basic shapes like Line, Rectangle, Triangle, Circle, Oval. The Line can be drawn in eight directions on a 2D plane and can be moved by ...
1
vote
2answers
49 views

Building a Building - Is the building clean?

I'm writing a small game and I use Kotlin for that. I want to model my buildings with the following class: ...
3
votes
1answer
41 views

Design - prevent multiple nesting in function

I have a function written in Groovy which needs to save a record and also return response from the server. Function is working fine, but I am not happy with the design because I have a problem with ...
-1
votes
2answers
63 views

Multiple inheritance of class broken up into modules [closed]

I have a class Main that uses fn(cls, ...) methods from several modules; they're used exclusively by ...
2
votes
1answer
38 views

Retrieving unspecified function arguments from external context (scope)

The Problem I have a module with several sibling classes that share a method with a similar name. These methods receive the same basic arguments, however, for a number of the sibling classes the ...
3
votes
2answers
144 views

Overloading == for better readability

I was working on a project recently that had a good amount of business logic associated with status codes. To better understand the flow of logic in the domain layer, I created an enum ...
3
votes
2answers
57 views

Print input one word per line (K&R 1-12 exercise) attempt

I'm currently trying to learn C from the K&R book, reading through and attempting the exercises. I came across exercise 1-12 yesterday and was a little stumped but managed to complete it. I was ...
-1
votes
1answer
59 views

Legacy Code Refactoring [closed]

I have a legacy piece of code and trying to simplify it. It's very tightly coupled. The problem is one method is called from another and other from another and so on this chain continues. Would ...
3
votes
0answers
48 views

Snake game with multiple snakes

Firstly, I wrote standard snake game, then I decided to increase difficulty and made game with various snake number. My main point was to try the curses module, the second - to create game with OOP ...
3
votes
1answer
45 views

Staff Scheduler: Design/Algorithm questions (Python)

Background I worked at a community center where everyday one of my coworkers would spend 20ish minutes trying to organize the day's schedule. The facility had three rooms: The Great Hall, The Club ...
2
votes
0answers
21 views

Add VMs and corresponding replications to VMGroups in a Hyper-V cluster

I'm looking for input on how to improve a powershell script I wrote. Im especially looking for suggestions, that I might be able to apply to future projects as well. Like (anti-)patterns I'm not aware ...
2
votes
1answer
157 views

What is an efficient ways to parse a bar separated usr file in Python

I am trying to create a robust, generic way to parse a bar delimited usr files, now I can read the file in and separate it by | ...
1
vote
0answers
39 views

DDD design: Tracking price calculation progress and fallback price calculation

I am pretty new to DDD, so any help/ideas will be appreciated. I will explain my initial design and problem below. The user can ask the system to generate products proposal, proposal is basically ...
2
votes
1answer
46 views

Presenter pattern implementation

I've recently discovered patterns and decided to implement Presenter pattern inside a pedagogical project. I spent few days playing around with different implementations, reading some Gem's source ...
1
vote
1answer
91 views

From procedural to OOP

I recently discover by reading some blog topics on web that 90% of code lines I produced in my career was procedural and not OOP oriented (big slap in the head). So now, I try to lobotomy my brain in ...
1
vote
1answer
48 views

Chain of responsibility and handlers dependent on each other

I'm importing data from file to many tables in database. It may look like this: First Name, Last Name, Meeting John, Doe, 2020-04-24 08:00:00 Some fields like "...
2
votes
1answer
58 views

How to make it more Scala compatible?

When you write a code in python code people always ask to make it more pythonic. I am not sure if there is a term for scala or not. However, I am pretty sure my following code use one or two scala ...
2
votes
1answer
99 views

Small Javascript Lib to draw SVG file

I'm new to JavaScript and I decided to make a script that allows other developers to show SVG elements in the web browser. (It is just for learning purposes), and it is still under development. I ...
3
votes
2answers
54 views

Scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This is a pretty huge question, however, I would appreciate it if you could just review the design and not my implementations of it. The Implementation and test sections could be ignored, they are ...
-1
votes
2answers
47 views

A better OOP way for solution

I am implementing a functionality in Scala to Copy files from one FileSystem to another ...
2
votes
0answers
50 views

Mapping an object tree to another object tree

Programming to an interface is a design principle that enhances the flexibility of software by hiding implementation details. Consider an object tree that only exposes an interface, but you want to ...
4
votes
1answer
83 views

How to design shopping cart Java application which satisfy modular, extensible and maintainable

I am new in Application Design. I have use-case as below As per the above story I have implemented code as below without any Modularity, Extensible and Maintainable. Could someone share the thoughts ...
4
votes
2answers
92 views

Quickly throwing together a text-and-button-based client-server web game

With much of the world in lockdown at the moment, my friends and I wanted a way to play our favourite game, Celebrity, over video chat. This seemed like a fun coding project, so I put together a ...
1
vote
3answers
212 views

Create UIView programmatically in Swift

I am generating View and setting constraints programmatically in UIViewController ...
1
vote
3answers
102 views

I want to take away WebService call from UIViewController

I am using Moya to make network calls in Swift. In my ViewController I am calling the WebService and creating a model from response. ...
3
votes
3answers
102 views

Calculator Object Oriented Design

I am aiming to implement a calculator in an object-oriented way. Here is the solution by using the strategy pattern. Looking forward to some valuable comments. ...
3
votes
1answer
78 views

Building an email generator using abstract factory pattern

I'm trying to build a customer email generator in java using the abstract factory pattern. I understand how to use the factory method pattern; however, I'm a bit confused about the abstract factory ...

1
2 3 4 5
26