A design pattern is a general reusable solution to a commonly occurring problem in software design.

learn more… | top users | synonyms

1
vote
1answer
48 views

How do you pick the strategy for the strategy pattern in the first place

It is the case where data contains some field indicating what type of strategy should be picked. I mean, I often ignore solving the problem like shown below and duplicate the problems that strategy ...
1
vote
1answer
39 views

Python file reader/writer, with processing pipeline and context manager

The following code does three things: The filename is determined by the RawData class The reader and writer send data through a processing pipeline (Hopefully) makes changes and extensions easy ...
5
votes
1answer
72 views

Write a program that, given an age in seconds, calculates how old someone is in terms of a given planet's solar years

Problem: Write a program that, given an age in seconds, calculates how old someone is in terms of a given planet's solar years. Earth: orbital period 365.25 Earth days, or 31557600 ...
2
votes
1answer
32 views

Form validation in core php with oops concept

Here, i build one form validation script in php using understanding SOLID concept. My question is the way i coded my code is true way for ...
3
votes
1answer
63 views

Write a small archiving program that stores students' names along with the grade that they are in

Problem: Write a small archiving program that stores students' names along with the grade that they are in. In the end, you should be able to: Add a student's name to the roster for ...
3
votes
1answer
39 views

Composite implementation of a prototype singleton registry

I am studying design patterns and I've implemented a composite prototype pattern which is also a singleton (one instance per JVM). The main and most important part of the code is the ...
1
vote
0answers
24 views

Save Custom Product Kit using Web Application

How far do I break down individual tasks within a typical scenario of "Web application reacts to user input"? For example, in the case below, say a scenario is "User submits a form, causing user data ...
4
votes
2answers
118 views

Simple builder pattern implementation for building immutable objects

This is a builder pattern implementation to build immutable Person objects: Person class ...
1
vote
1answer
33 views

Old and new shouts controllers

I have a photo_shouts_controller.rb and text_shouts_controller.rb which both have almost similar implementations, and I would like to refactor it. I have implemented a refactoring but I am not too ...
1
vote
1answer
45 views

Implementing builder pattern In Java with a static inner and a Concrete standalone class

I am studying Gang Of Four design patterns and I want to implement a builder pattern in Java. It seems there are two options to build a builder pattern: Using two different classes: A target class ...
0
votes
1answer
25 views

Singleton manager/service classes with mockable dependencies in swift

In our swift project, there are multiple service classes that encapsulate functions, mostly network-api calls. They implement a protocol, and depend on other service classes, e.g. an authorization ...
2
votes
2answers
70 views

Simple singleton database connection pool

I'm studying design patterns, and to demonstrate a singleton, I've implemented a primitive database connection pool. ConnectionPool.java ...
-4
votes
1answer
39 views

Am I violating the SRP in this code? [closed]

Here's a sample code that I made up : ...
7
votes
1answer
95 views

Repository Pattern without an ORM

I'm trying to learn the Repository pattern, and I have some questions regarding my current understanding of it. All the examples I've been able to find of database repositories use ORMs, but for a ...
2
votes
0answers
48 views

Design Patterns in Swift: Visitor

I'm solving the following problem using the Visitor design pattern in Swift: When a quote is requested or an appointment is booked we send out an email to the customer, and build an internal ...
0
votes
0answers
15 views

Design Patterns in Swift: Strategy

I'm solving the following problem using the Strategy design pattern in Swift: We order our parts from three different vendors. Each vendor has its own system for verifying and fulfilling parts ...
2
votes
0answers
35 views

Retrieving the most recent posts from the users someone is following

I have two different implementations for retrieving posts from the users someone is following and I want to know which one you would recommend using. First I'll show you the tables, and then the two ...
2
votes
2answers
66 views

Design Patterns in Swift: Mediator

I'm solving the following problem using the Mediator design pattern in Swift: Assume we track the location of all our mobile mechanics. We have noticed that there are times when a mobile ...
2
votes
1answer
36 views

Design Patterns in Swift: Chain of Responsibility

I'm solving the following problem using the Chain Of Responsibility design pattern in Swift: Not all mechanics are created equally. Some mechanics are more experienced and can do more than ...
5
votes
2answers
58 views

Menu Model class using Model-View-Presenter

The following code is for my Object Oriented Programming class. My program simulate the cashier's machine to order food. The code uses Model View Presenter. This class is the model. I have an ...
3
votes
1answer
51 views

Observer design pattern in Swift

The problem: We have a set of mobile mechanics who are assigned specific zip codes. Each zip code has its own hourly rate. We want to increase and decrease these rates when the number of idle ...
6
votes
3answers
117 views

View programming pattern in C++ without raw pointers

I'm trying to achieve, for lack of a better term, a "view" pattern in C++. It's probably most comparable to "views" in the Database world, where one can make a query, and then perhaps aggregate the ...
2
votes
0answers
43 views

Signing timestamped API queries

The following code should prove to offer sufficient security for public API so my main concern is about design flaws in process. It is meant to describe the process and eventually get included in ...
-3
votes
2answers
105 views

How can I refactor this method in C# with a design pattern? [closed]

I have this method in C# that could be refactored. Should I use a design pattern? I see too much repetition and it gets worse if more conditionals are added. Should I change it to a method call? ...
3
votes
0answers
53 views

Shape inheritance hierarchy

I have managed to build an inheritance hierarchy for shape class object and I am wondering if there is a better solution to combine the following 2 hierarchies. To begin, I have a 4 shapes classes ...
2
votes
2answers
49 views

Sending an SMS message using zenoss and python

I have just finished a simple python script which uses this module to call Zenoss API for getting live events. What the script does: connects to zenoss reads a file which has one phone number on ...
1
vote
2answers
686 views

Which is correct : Open one Connection for inserting List of objects or open connection for every single insertion?

I have written the following method twice but I don't know which is better from performance perspective, code design and best practice. First: ...
1
vote
1answer
80 views

Implementing Entity and Component in a game engine

I'm currently creating a game engine for my personal project. And I'm currently implementing Entity and Component System. Classes and Interfaces Definitions Here the classes and interfaces that ...
0
votes
1answer
55 views

Long running in-process Publish/Subscribe class

I have a Pub/Sub class that will call Notify() when published and that Notify() could take around 10 seconds, so I need to make ...
3
votes
1answer
111 views

UDP Server Design and Performance

What I'm doing I am writing a server to work as my games backend. The server is being written in C# using UDP as the protocol, while the game is in C++. The biggest thing I've been focusing on was ...
5
votes
1answer
166 views

Reading a properties file using design patterns

I am trying to read properties file using a singleton class. I would like to know if there are any best practices and design patterns to read the properties file. I found dependency injection is one ...
2
votes
2answers
205 views

Implementation of Abstract Factory pattern with different vendors for product

I am studying about design principles and design patterns. I have implemented an Abstract factory pattern as per my understanding. The scenario I have considered is as follows : There is an ...
0
votes
0answers
17 views

Reusable Properties File Reader [duplicate]

I have implemented a properties file reader. The goal behind creating the properties reader is to cater to different application teams to import the class and read the properties in their projects. ...
10
votes
3answers
165 views

Pokemon stats calculator

I have a simple working (so it's not a hypothetical stub) framework for calculating Pokemon stats that will later be incorporated in a game. It uses the LCRNG from the first game in order to be as ...
3
votes
1answer
68 views

Application Settings Helper

I'm developing an app which stores some different user settings in app.config such as connection strings, paths for saving reports, default printer e.t.c For retrieving them I made a static class ...
2
votes
2answers
70 views

Module pattern JavaScript to initialize page, add event listeners, load map

I've written a script that I would love to get feedback evaluating the following: Module Pattern implementation, robustness, conciseness, cross-browser compatibility. My goal is to eventually use this ...
1
vote
1answer
83 views

Throwing exception in the singleton pattern in C#

I'm implementing an HTTP client shell that's going to be used for the lifetime of my application in C#. It needs to be initialized before the instance can be accessed. It looks something like this: ...
0
votes
0answers
33 views

Command and observer pattern to build installer wizard

I've done this mainly as an exercise to understand these design patterns. I'm writing a theoretical install wizard which will allow users to select different options throughout, and have it execute ...
2
votes
2answers
48 views

Instantiating different kinds of error records for a database operation

I've written code to be called from Powershell like so: Rename-DatabaseUser -Name 'someuser' -NewName 'somenewuser' I'm wondering if there's another way I can ...
2
votes
1answer
51 views

Convert custom format to XML Template

I have just finished writing a simple Python3 program which converts a custom input file (or multiple files within the same folder) to an XML template. It works as it is, but I think that I somehow ...
2
votes
2answers
117 views

Strategy pattern using an abstract class and an interface

I have implemented some sort of the strategy pattern using an abstract class and an interface: ...
1
vote
2answers
101 views

Instantiating shapes using the Factory Design Pattern in Java

Trying to learn the factory design pattern, came up with some code based on a Shape Factory (found this example here). Is this the right way to implement the factory pattern? ...
14
votes
1answer
195 views

Simple dictionary storing/viewing application

A TreeView on the left which just displays a list of files saved by the application. A DataGridViewon the right to display data ...
0
votes
1answer
35 views

ViewModel class in Typescript

I am trying to refactor a ViewModel class because it has two methods that are really similar called updateRegions and ...
6
votes
2answers
162 views

Dependency problem in C#, through polymorphism, and appropriate design pattern

I'm currently working on a project which involves EntityFramework with a (very) rich model (lots of inheritance). I'm currently facing a problem, quite interesting in my opinion. My model is ...
5
votes
1answer
75 views

Custom Navigation Bar View Implementation

In one of my app, i m using custom navigation bar view to handle all Navigation Bar Properties. Is it good practice to use custom navigation in given below way? Any Optimizations need to be done. It ...
8
votes
1answer
278 views

Business with dbcontext and static class

Many speak of using dependency injection. I do not use repository. The entity framework is uow/repository. What is wrong with using static class like the one below? My context is a new instance per ...
2
votes
0answers
35 views

Implementation of MVC in Java

I've followed several guides on how to implement MVC in Java, and so far I've come up with the classes shown below. From my understanding, MVC follows these guidelines. The Model should be ...
5
votes
1answer
59 views

Message Service

Below is the code to a Message Service. Does anyone have any ideas on how to improve the methods. It doesn't feel clean to me. ...
-1
votes
1answer
39 views

LINQ to SQL code - in models project or in db project

I currently have two projects. One called Models, a second called TaskEntityModels, a model first ...