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

learn more… | top users | synonyms

0
votes
1answer
26 views

Image-processing filters using decorator pattern in Python 3

The goal of the following short Python 3 program is to improve my understanding of the decorator design pattern. Therefore, I would be mostly interested about feedback on this aspect, i.e. whether ...
2
votes
0answers
36 views

Java member method initialization pattern

To avoid the overridable method call in constructor dilemma this approache delegate the variables initialization and calls to overridable methods to a member method that return reference to the ...
0
votes
0answers
22 views

Is it okay to use static classes while creating a wrapper for REST API? [on hold]

I am consuming a web service in C# using REST APIs. So, I have created a wrapper classes for each endpoint. It seems like a good idea to implement the wrapper using statics. This makes code look much ...
2
votes
0answers
33 views

Input-reading library for Node.JS part 2

Note: This code is a rewrite of the post I mentioned here since according to CR policy I cannot update the same question. This is somewhat didn't went through that much thought process and I wrote ...
0
votes
0answers
25 views

What do you think of this pattern to iterate over Objects and return a new Object? [closed]

This function merges multiple objects that only contain strings into one new object. If a key appears more than once it concatenates its values. The objects that the function has to handle store css-...
3
votes
2answers
75 views

Validation Error Handling - DRY Pattern Implementation

The Country, State and City functions accepts the Integer as Parameter and returns the ...
0
votes
0answers
15 views

Inheritance is better or composition design pattern in this scenario? [migrated]

Design and implement Cash Register: Given a number of items you will be required to calculate the total bill. Items are charged for in a couple of different ways: A given price for each item, e.g. ...
4
votes
1answer
74 views

Rock-Paper-Scissors with the revealing module pattern

In my ongoing effort in learning advanced JavaScript I tried to develop the traditional rock paper scissors game by using the famous revealing module pattern. I'm not comfortable yet with what has to ...
3
votes
1answer
70 views

Factory method that constructs objects that represents MySQL data types from query results

I'm writing a package that is designed to provide a convenient way to inspect the schema for a database. The goal is that I can use it for generator code to suit the schema. The complete code can be ...
0
votes
0answers
18 views

Event log implementation with TDD

Below is some code that implements an 'event log' whose purpose is to record events and periodically check that all events were recorded in chronological order. The collection of events must be ...
3
votes
1answer
79 views

Simple Wizard Goblin User Story Test Driven Development

I have written this to practice Test Driven Development. I would like to know if the process is right and how it could be improved. Problem Statement : A wizard can cast spell on goblin and make his ...
5
votes
2answers
98 views

Illumination as a way of instantiating new objects

Basically, what I mean by illumination is having a method create an object where the caller supplies all the dependencies. This allows us to hide our new keyword ...
4
votes
1answer
100 views

Using a LinkedList type of adjacency list to create the word game: WordLadder

Goal The user puts in a starting word and an ending word. My code creates a ladder between these words of words that are different by one letter. Start: gain End: fire Output: gain gait wait wart ...
-1
votes
2answers
67 views

Java dog hierarchy

I am supposed to write a small java program. The program must contain 3 different kind of dogs. The dogs can bark and move, these methods can be represented just by System.out.println();. Some dogs ...
3
votes
0answers
22 views

Mini school database with JS revealing module pattern

I tried the module pattern for the first time, with this exercise as a problem to solve: http://exercism.io/exercises/javascript/grade-school/readme It's a small exercise requiring simple tasks : ...
6
votes
1answer
88 views

Creating a Kinesis stream, Firehose, and lambda event source from config file

I'm in the process of writing a python script for automating a data ingestion pipeline using Amazon Web Service's Kinesis stream, Firehose and lambda. This is my first stab at writing Python, but I do ...
4
votes
2answers
89 views

DB-to-Java value mapper

In my company, I've inherited some Java library that I'm now writing tests to, refactoring and fixing Sonar issues. One particular point that Sonar is complaining about is a big chaining of ...
1
vote
0answers
27 views

Abstraction of NSNotification that removes the existing observer for a notification when a new observer is added

I ran into a problem in my app where under some conditions, a view controller might be loaded more than once before its deinit (where I was previously removing the observer) is ever called. So the ...
1
vote
0answers
54 views

Refactoring ValidationContext from inheritance into decorator

In one of my questions I used a ValidationContext class that looked like this: ...
3
votes
2answers
104 views

Command pattern with structs

I'm using the command pattern to enable actions in my game to be undoable. ICommand defines individual commands, ICommandHandler does the undo-redo logic and might be decorated with other handlers ...
1
vote
1answer
109 views

Call Center Design

Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can’...
1
vote
2answers
96 views

Properly structuring SQLite classes/operations in Android

I am new to Android development and I want to ensure I'm learning decent practices for doing things. Right now this is my database class, which currently allows me to make a new instance of the ...
2
votes
0answers
46 views

Data structure of in-memory database [closed]

I am learning OOP, SOLID principles and design patterns. I have designed data structure of in-memory database in C#. Please provide suggestions to improve it better considering solid principles, OOP ...
4
votes
1answer
95 views

Basic Internet banking application

I programmed in Java before, but I feel that I lack the "true way" of programming (OOP concepts, design, algorithm), so I started to learn all of these but I need your opinions and suggestions so I ...
2
votes
4answers
168 views

Implementation of warning storage

I implemented type (UserRuleManager) that will apply list of rules to entity User. I need your code review and your advices. ...
0
votes
0answers
60 views

My take on implementing the Repository Design Pattern in PHP

The past few weeks I've been trying to grasp on nearly any Design Pattern ever invented, but the repository pattern is one I could understand and implement it myself in my project. My application uses ...
4
votes
1answer
73 views

Use of Module Design Pattern in simple D3 “overlay” program

I have been learning JS (mostly using D3) and I wanted to put the Module Design Pattern to use. I wrote a simple script that lets you build a bar chart with more ease / readable code. The end user ...
4
votes
0answers
36 views

implementing a StringEnum

this is to be used like an Enum (as parameter mostly), but for string using .net 3.5 Actual Implementation ...
2
votes
1answer
82 views

Map rental cost strategy

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
45 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
85 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
91 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
78 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
43 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
27 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 ...
5
votes
2answers
159 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
37 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
50 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
56 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
161 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
41 views

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

Here's a sample code that I made up : ...
7
votes
1answer
112 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
56 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
21 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
38 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
77 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
48 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
69 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
67 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
121 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 ...