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

learn more… | top users | synonyms

5
votes
1answer
42 views

Design pattern for implementing multiple data sources

I've written a program to populate a particular object from multiple data sources, however I'm not convinced I'm going about this in the right way: I have no idea which (if any) design pattern I ...
11
votes
3answers
421 views

Is decoupling necessary for very small applications?

I threw together a small solution for my organization today for some basic data review and approval procedures. This particular application will likely not change or add functionality at any time. ...
2
votes
0answers
31 views

What can I do better in this ViewModel Creator?

I'm currently creating a ASP.NET MVC page in C#. I want to hide everything regarding the creation of our "models" and "viewmodels". I have seen much of the fancy stuff regarding Dependency ...
6
votes
3answers
106 views

Factory for classes unknown at compile time

I have a class called Machine. It contains a list of parts and a list of actions. The list of parts will contain instances of the Part class subclasses and the list of actions will contain instances ...
4
votes
0answers
32 views

Is this a sensible way of using an IoC container?

I have a Factory class for a queuing system I'm playing around with. Consuming classes only care that they get a particular interface (Job) as a result of calling the factory's load method. Some ...
2
votes
1answer
63 views

Run a TCP server listening for incoming messages

I've written the following code, but I need some review on design style. I want to develop a library/module and expose an API to client programs. How do I do that? The code just runs a TCP server ...
4
votes
1answer
55 views

PHP magic function for accessors and mutators

I have implemented the following PHP magic method behavior to save my time of creating accessor and mutators for properties of any class that extends this base class. I am looking for suggesiongs on ...
2
votes
2answers
100 views

Creating linked list data with iterator pattern

I've created a linked list to use it in SquareList. I've started to create a linked list based on just that. I want my class to follow the iterator pattern. How can it be improve to use vector ...
1
vote
0answers
62 views

Code First/Database First Entity Framework MVC [closed]

The following example is taken from the book Pro ASP.NET MVC 4 - Adam Freeman. This book does a good job going over the basics of the MVC framework. In it a database is created from a Product class ...
12
votes
4answers
810 views

Better way to manipulate this string in sequence?

I am working on a small custom Markup script in Java that converts a Markdown/Wiki style markup into HTML. The below works, but as I add more Markup I can see it becoming unwieldy and hard to ...
8
votes
2answers
132 views

Handling null arguments in a factory class

I have a Factory class that gives out instances of ResponseImpl class. It accepts one Destination class and up to four Source classes. At least one of the four Source classes should be not null. So, ...
0
votes
0answers
35 views

How to display domain object summary information efficiently when there are many types? [migrated]

I've provided only simplified code as it's more of an abstract design question. So I have many, many nested business/domain event objects, e.g. public class Event { //bunch of properties and ...
9
votes
2answers
105 views

Simple specific classes design

I am new to c#, and rather new to design-patterns. I want to create a simple and a most elegant solution for loading and validating a xml file and later on extracting its fields. I've started with a ...
8
votes
1answer
132 views

DTO pattern: what is the right way to tell client that there is no result?

This is how I handle this situation right now: For example, I have service that returns UserDto by user ID: GetUserById. Service never returns null or throws exceptions. Service always returns DTO ...
4
votes
1answer
68 views

Reducing nested while statements for building a grid?

I have the following grid shape: __ __ __ |__|__|__| |__|__|__| I have the following 3 types of shapes to fill it (they cannot rotate): __ |__| __ |__| |__| (6x6 one above, or full size) ...
8
votes
2answers
175 views

Implementation of the Strategy Pattern using an interface, abstract class and delegate

The following class was designed to help create a more detailed error message than what's provided by the repository when a user tries to insert text into a column that is > the column max length. The ...
3
votes
1answer
96 views

Abstract Factory + Strategy pattern for parsing log files in multiple formats — improvement suggestions?

I'm writing a service to parse machine log files as they are written to a central directory and push them to a web service. Each machine generates several log files at a time, with each file ...
3
votes
1answer
80 views

Use of the composite pattern

Assume the following requirements: Is it a good idea to use the Composite design-pattern for this, taking into account that there will be: Only 1 TestPlan a TestPlan can only have TestSequences a ...
3
votes
2answers
86 views

Python coding style from Java background

I am pretty new to Python and just wanted to make sure I am going in the right direction with my coding style. After reading this, I'm not so sure. The following is a convenience class that has ...
2
votes
1answer
47 views

Design To Handle Multiple Similar Model Class

I am doing a web app for an event company whereby customer can access the website for a self-help instant quotation. Customer will choose the type of event, fill a form and expect an instant ...
1
vote
1answer
76 views

using (IDisposable) in c# factory pattern

How will this example affect the using implementation in GetSite? public abstract class SPSiteBase { protected abstract string Url { get; set; } public abstract SPSite GetSite(string url = ...
0
votes
1answer
126 views

Understanding Dependency Injection and Inversion of Control

I have recently been looking into the concepts/patterns behind dependency injection, inversion of control, and registries/service locators. I have searched about the internet on the subjects and have ...
1
vote
1answer
81 views

Unit of work and common implementation

I have some questions regarding a common implementation of the UoW, Repository Pattern and EF: public interface IAppUow { void Commit(); IRepository<Customer> Customer{ get; } // ...
4
votes
1answer
174 views

Implementing SOLID Principles with C# Asp.net

I have started learning about SOLID principles from yesterday. I've got a detailed explanation of SOLID principle here. After reading it and few other articles, I have tried to apply these principles ...
8
votes
5answers
251 views

Abstract Pet class

As a student of C# right now, I am trying my best to get a grasp on many of the systems being taught. I just completed Week 1 of a C# 102 class and the class was assigned a bit of homework. I am ...
2
votes
1answer
79 views

Javascript code pattern

I have been working on a javascript heavy project. There are sales, purchases, reports etc. What I've done is created a separate module for each i.e. a separate module for each i.e. a separate one for ...
5
votes
7answers
304 views

One instance per method call or multiple method call per instance

I have the following class designs, and I'm looking for the best practices, aligned to the OOP design principles/patterns. The ParameterParser will be used inside a foreach block through 10 items ...
4
votes
2answers
59 views

Ruby Dynamic Struct - Pattern or AntiPattern?

There is a pattern that keeps coming up in my ruby code and I'm somewhat ambivalent about it. It's somewhere between a Hash and a Struct. Basically I used method_missing to return/set values in the ...
5
votes
7answers
240 views

Which pattern to choose for passing alerts from service method back to user?

Considering the code sample below, which approach of service method design would be considered best-practice and why? The one used in SaveOrder1 or the one in SaveOrder2? UPDATE: To be clear, I'm not ...
1
vote
4answers
139 views

Feedback on logic implementation of PyQt4 based Image gallery using QTableView

I have made an application to display images in the form of gallery, from terminal if you are standing at the same location then it will open those images in the gallery if it does not have it will ...
2
votes
1answer
84 views

Best design pattern to approach http handler with multiple methods

I'm building an http handler at work which has about 6 methods and I'm trying to figure out what design pattern will work the best for my needs: What's done already (Only an example to make this more ...
3
votes
2answers
118 views

Image loader/writer design (no API, pure C++ on Windows)

So, I have an image loader, now only for bitmaps. I'm a little confused because I want to split my code to different classes, one for writing a BMP data to a file (WRITER), one for loading BMP data ...
4
votes
2answers
153 views

Using the observer pattern with collision detection

My Game class has a property of type Player, which inherits from Entity: player = new Player( "knight.png" ); It also has a property of type World, which has a collection of Entities (Robot ...
5
votes
1answer
81 views

Is this a good way to cascade a property?

I'm trying to write a simple game. I have an Entity object, that has a list of Sprite objects. Each Sprite has a position property where it is drawn on the screen. Sometimes, an entity can contain a ...
2
votes
1answer
68 views

Very basic Context Free Grammar in Java

I wrote this program for an assignment, thus I had some requirements as far as the format of the cfg.txt file and some basic other classes that we had to use. Other than that, I am curious if there is ...
2
votes
0answers
96 views

Alternate initializer pattern in Python [closed]

from collections import namedtuple import functools import unittest # The following example is contrived and over-simplified. class Vehicle(object): def __init__(self, name, passengers): ...
0
votes
0answers
31 views

Compose in Javascript - Go ahead with this example?

I'm trying to use the good parts of Javascript and dont follow the classical inheritance. I studied and created this example of compose in Javascript, https://gist.github.com/fernandoperigolo/7789866. ...
2
votes
0answers
173 views

Modelview programming in PyQt4

In my first attempt, I have tried to load images from disk and load it to a QTableView using QAbstractTableModel. I'd like a general code review of this code. import sys import os from PyQt4 import ...
2
votes
1answer
180 views

Is this correct usage of Repository + Unit of Work + Service Pattern

I have project where I need to use C# and Entity Framework. After my question here, I have decided to use Unit of Work and Repository patterns. This is the first time when I'm using this. Can ...
5
votes
2answers
208 views

Generic DAO written in Java

I initially thought that this was just an architecture issue so I placed it on programmers as Thoughts on refactoring a generic DAO. Then I asked on codereview meta here and decided to put up the code ...
1
vote
1answer
68 views

Feedback on logic implementation and testing

This is my forked branch attempting to make the code better, This is an application for having a slide show of photographs in current directory or supplied as argument. Use keyboard controls[left to ...
3
votes
2answers
76 views

Javascript velocity converter, fully chainable

I created this out of curiosity and it has some code duplication issues and the fact that sticking .yield() on the end of a call to a unit converter is pretty strange. How would you improve it? /** ...
2
votes
3answers
78 views

Refactor if statement with object-oriented style

I've this block of code: Edit: more accurate code: public void Execute() { ... var memo = BL.GetMemo(); ... if (memo.testCond1()) //like memo.isLongText() doSomething(); ...
8
votes
4answers
289 views

Design battle - comparison between two approaches, which one is best?

Link to my Stack Overflow question. Recently I've been learning about design patterns - Now I decided that I know enough to be able to refactor my inventory code. In an inventory, there's items, ...
1
vote
3answers
70 views

CSV file cleanup

I'm fairly new to Python and am going to be parsing hundreds of thousands of names eventually. What I wanted to do was take individual CSV files, and create new CSV files with only the info I wanted. ...
4
votes
1answer
94 views

Developing a better state pattern in C

gcc (GCC) 4.7.2 Hello, Is there way to create the state pattern in C? I have created a state diagram to show the different transitions and states. I could not find many examples of the state ...
8
votes
3answers
273 views

Validation class to avoid ugly if-else blocks

I've answered this question on Stack Overflow. The problem is - there are 30 columns in an Excel sheet and I need to validate each of the fields with different validation logic. The code should avoid ...
2
votes
0answers
56 views

Encapsulating behavior spread across multiple event handlers

I wrote a chatbot in Ruby for turntable.fm, a chatroom where users can listen to music together. It interacts with users in a room, who can type in specific keywords and get responses from it. It also ...
8
votes
3answers
294 views

Why would I want to always have to explicitly call a “base” method if I just want to use base functionality?

I recently worked with an architect who structured his base class like this: public abstract class Base<T> { public abstract T Get(int id); internal T InternalGet(int id, ...
3
votes
1answer
183 views

JavaScript Module Pattern with AJAX

I have an application which currently uses AJAX for CRUD operations on a simple Person object. The following script works fine, but I'm looking for some pointers on how to structure my code. ...