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

learn more… | top users | synonyms

2
votes
1answer
56 views

Do I need ninject when implementing DAL with generic repository and unit of work?

I am implementing generic repository and unit of work for the first time. I would be glad if someone can correct me if I am doing something wrong here. This is how I communicate with my DAL from ...
3
votes
1answer
60 views

Confusing control flow

Currently, the following code runs and produces the expected and desired output. However, I'm sure that there's much wrong with it. This project queries the (flat) database, instantiates each row as ...
3
votes
0answers
43 views

Debug log wrapper

Please review code correctness, best practices, design and code formatting. I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I ...
4
votes
2answers
186 views

Factory design pattern example in C++

I found a definition of the factory design pattern as: "Define an interface for creating an object, but let the subclasses decide which class to instantiate." I understood the first part "defining ...
0
votes
1answer
56 views

Command line multipart or single file downloader

I am looking for a code review for this multipart or single file chunk downloader using threading and queues. downloader.py ...
3
votes
1answer
43 views

Refactoring this producer consumer class to minimize what is exposed

I don't like the service class below, specifically, the way it exposes the internals of the producer. While it would be possible to combine all three classes into one producer-consumer, I would ...
2
votes
1answer
40 views

Factory style pattern in method

I have a method in a class, and its sole purpose is to prepare another class for use: ...
5
votes
3answers
78 views

Text-based Blackjack game in Python

I am new to programming in Python and wrote a simple Blackjack project. I am looking for experienced peers to provide a high level code review about the overall design patterns and proper usages. The ...
2
votes
1answer
54 views

Basic PHP Factory Pattern

I have an object, KbArticle, that originally in it's constructor, would try to return null if the SQL query that retrieves the data for its required properties came ...
1
vote
1answer
42 views

Concept for saving context information

My Problem I have a library containing business logic which is being used from 3 different projects: Website Local WPF Application WCF Service The library uses Entity Framework and a connection ...
6
votes
5answers
166 views

Casting base to derived class according to a type flag

I have been writing an event class for my game engine and I came across to the following problem: Is casting a base class object to a derived class object given a type flag a good programming design? ...
4
votes
1answer
50 views

Builder/named argument/fluent interface pattern with unique_ptr

I'm trying to figure out the cleanest way to implement a fluent interface with unique_ptr and other "modern" C++ language constructs. Here's my first attempt: ...
4
votes
1answer
87 views

First attempt at making a user class

I've just begun creating my first user class. First, I need some clarifications. Am I using try and catch correctly? To ...
9
votes
2answers
301 views

OO design for Tic Tac Toe program

I am practicing object oriented design and have taken Tic Tac Toe as an example. I have written first all the requirements and then started writing code. I would like to get it reviewed so that I can ...
1
vote
1answer
44 views

Unity DI Composition Root vs XML [closed]

I'm having trouble figuring out the best approach with DI. After doing more research, Mark Seeman recommends using the Composition Root approach. In my example, I am using XML configuration to design ...
0
votes
1answer
49 views

Use of getters and setters with a car information example

I have very quickly mocked this up as an example model in Angular JS: ...
5
votes
2answers
65 views

DRYing up an initialization pattern

I maintain a VBA process that prints a large number of PDFs. It was awful when I inherited it and I've been making improvements over time, but I'm a bit stuck on this one. There are at least 4 ...
3
votes
2answers
31 views

DOM building using DocumentFragment

I want to build the markup below by iterating on an array of objects. The structure of the object is also listed below. I need some tips on how to make it clean. Markup I want to build: ...
7
votes
2answers
110 views

Basic snake game

Coming from a Java background, this is my first JavaScript-only game. I'm looking for some advice on what to improve. Also, I'm having trouble when it comes to program design. Sometimes I don't ...
6
votes
2answers
98 views

Is this a correct use of using protocols and delegate pattern in Swift?

I am trying to grasp the concept of delegates and protocols in Swift. So I have implemented my own PlayableMedia protocol with two concrete classes ...
0
votes
0answers
19 views

Re-factoring restrictions validation functions for proper OOP design in MVC framework

I am aware that code review is for refactoring code from an existing code. Let me first to say that the following code works but inefficiently and its very convoluted, so I would like to apologize if ...
11
votes
2answers
219 views

Input handling system using the command pattern

The online book Game Programming Patterns briefly describes the use of the command pattern to handle input in a game. I've attempted to write my own "one size fits all" input handling system based on ...
4
votes
2answers
80 views

Would this be considered MVC?

For many days, I've been re-designing my application, applying some custom pattern and making our code looks like a framework. I have something like this for separate the business logic, from views: ...
3
votes
1answer
66 views

Should I null coalesce EventArgs?

When I implement events, it usually looks something like this: ...
5
votes
1answer
68 views

Message Based Communication Design

I'm trying to design an API.NET for some communication purposes with Testing Equipment and I cannot figure out a proper way for designing the architecture. Basically, we have different (physical) ...
4
votes
4answers
90 views

How to name template method properly so it makes better sense?

Some might not think it's worth asking but I consider good function names quite important. I am not sure what should be the overridable function name in what I think is template design pattern. I am ...
4
votes
1answer
82 views

Unit of Work / Repository nHibernate

I have a Unit of Work / Repository pattern in place to abstract away some nHibernate. Most examples I've seen though use the pattern a little differently. In ...
6
votes
1answer
119 views

Abstract Factory Pattern C# Example

I am working through more tutorials on Design Patterns and came across the Abstract Factory Pattern. I extended it out a bit (the example that is) and want your opinion: ...
1
vote
1answer
36 views

How am I supposed to write a binary tree (S-Expression) pretty printer in C?

OK, I feel like I am doing something really wrong here. I'm just trying to create a binary tree, and a pretty printer for it. My approach is looking so bad I can't even... ...
7
votes
1answer
139 views

Unit conversion activities

Please review these activities which handle converting units in an Android app: I would appreciate any guidance and advice on code refactoring and different design patterns or strategies that I ...
3
votes
0answers
103 views

Laravel - Repository and Entity patterns

I've spent quite a bit of time studying the repository and entity patterns and this is what I came up with. I would appreciate it if you could post suggestions and critique. ...
3
votes
1answer
88 views

Model Implementation That Calls RESTful API

I am working on a ground-up rebuild for an app that has a relatively simple purpose. Users can view/favorite entities that are backed by a RESTful API. I own both the client code as well as the API. ...
5
votes
1answer
41 views

Secure Functions in a Database Class

I am trying to solve as many issues as possible with my Database Class and bind statements as far as possible without actually doing it in the front-end. The goal is to do all of the heaving lifting ...
3
votes
1answer
47 views

An attempt to extend an enum to prevent branching without violating the Open-Closed principle

I love making utility State enums, and giving them methods that do useful things based on which instance of the enum is provided. This works when the enum is very specific to the class I'm working on, ...
5
votes
1answer
147 views

DRY + principle of least knowledge + MVC in JavaScript

Is there any way of improving this code? (Here's a JSFiddle with an example and comments) Example: A Hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a ...
3
votes
2answers
62 views

Abstract factory pattern implemented in Java

I need a code review on my Abstract Factory pattern written in Java. Find the two enums AnimalType.java and DietType.java below. ...
3
votes
0answers
38 views

Proof of concept and learning exercise for the 'ports and adapters' architecture

The script creates a simple app with a GUI containing a input field and a button to select a folder. On startup a default value is set to the input field. If the user types a value or selects a ...
1
vote
2answers
199 views

Code duplication for just an if condition

I have two methods that are near-perfect duplicates. There is of course a code smell. The only thing that changes is the condition to increment a variable. Language: Java7 ...
4
votes
0answers
50 views

Static Multilevel Inheritance with CRTP (Fast Intrusive Pointers)

I wanted to have a way to be able to static_cast to the proper derived type pointer of a base class to simulate a virtual call. Here the virtual call is for a ...
0
votes
0answers
14 views

Need to provide an interface (for plugins) for taking input Type A, and returning output Type B [migrated]

public interface IMyInputProviderPlugin { IMyOutput Provide(IMyInput data); } This is an interface I need to provide so that I can dynamically load the dlls ...
2
votes
1answer
72 views

Is this a meaningful Intrusive Pointer Class?

Is this intrusive pointer implementation correct? I tried to use the CRTP Pattern to avoid a virtual destructor in my class ReferenceCounting which provides the ...
3
votes
1answer
88 views

Decoupling with a self-descriptive mediator function

I don't have a lot of experience writing libraries and just recently started thinking a lot about structure and patterns. I wrote a tiny module manager based on the facade and mediator design ...
5
votes
3answers
101 views

Use of mediator design pattern with mailing list implementation

I have implemented the following scenario for the Mediator pattern sample: MailingListMediator: Manages the subscription and send the mail back and forth. ...
9
votes
2answers
72 views

Scalability of running commands from user input

Here is some code I have that has been extracted and shrunk down from a project of mine. ...
1
vote
0answers
46 views

Creating a new marker on a map

Is this code good practice? What kind of design pattern should I use for this specific situation? The following function creates a new marker on a map. It sets a new image for it, except when the ...
0
votes
1answer
43 views

Factory Pattern to Abstract Factory Pattern [closed]

My Product Factory public interface IProdctFactory { void Drive(int miles); } My Vehicle Factory ...
1
vote
0answers
42 views

Is this model a good management for the pattern UOW / Repository with NHibernate?

Searching on Stack Overflow and Google, I find many and many different implementation but none of that really convinced me, each had some small defect that prevented me from using it. So I tried to ...
2
votes
0answers
51 views

Implement.js JavaScript module pattern

I have been playing with a new JavaScript module pattern to see what I can come up with. I think it's quite powerful and wanted to know if it is something people would find useful? I'm looking for ...
1
vote
1answer
82 views

Finding an entry in a Hashmap

I've been playing around with functional programming for a while now and just started learning Clojure. So the problem I'm trying to solve is the following: I have a tree-like hashmap of tasks where ...
10
votes
2answers
194 views

Decoration Freak, or OCP in action?

I'm writing C# code to read and eventually parse VB6/VBA code modules. I have an interface like this: ...