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

learn more… | top users | synonyms

3
votes
1answer
51 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
67 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 ...
1
vote
1answer
39 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
52 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
0answers
27 views

Loose coupling and shuffling dependencies [migrated]

I have a bunch of classes that look something like this: public class MyGame() { private Graphics graphics; private Player player; public MyGame() { graphics = new ...
0
votes
1answer
88 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 ...
2
votes
1answer
62 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
115 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 ...
7
votes
5answers
200 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
72 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 ...
4
votes
7answers
264 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
54 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
215 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
123 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
46 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
90 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
111 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
73 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
51 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
55 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
28 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. ...
1
vote
0answers
156 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
113 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 ...
4
votes
2answers
135 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
63 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
64 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
71 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
285 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
63 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
69 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
239 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
44 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
289 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, ...
2
votes
1answer
137 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. ...
1
vote
0answers
45 views

Sample design Oauth2.0 flow

I have the following code that I hope developers will use. [LKOauth showLogin: self data: data success: ^(NSString * code) { NSLog(@"%@", code); } ...
0
votes
0answers
99 views

Data pipeline processing framework

I'm trying to build a framework similar to Scrapy ItemPipelines or Pipeless. The motivation is to be able to build generic data pipelines via defining a modular collection of "pipe" classes that ...
0
votes
1answer
92 views

Am I implementing the Decorator pattern correctly?

I am learning design patterns, the book I am learning from (Head First Design Patterns) is in Java which I am not too familiar with so I may be making some errors. I have implemented a very basic ...
4
votes
2answers
246 views

Issues with this pattern to restrict access to private members?

Since the original post, I have explored further regarding this pattern. In an effort to fix one self-percieved flaw (the lack of ability of prototype methods to access private object members), I have ...
0
votes
0answers
69 views

Proxy/Facade Implementation Concept in C++11, impedance matching DB with classes

In an old project I tinker with from time to time, I have a DOM-like structure in an MMF database. I'd like the nodes to act like they have some C++ typing based on the content, and accessor methods ...
3
votes
2answers
103 views

Custom database Lock - implemented with IDisposable

I have a lock class, that handels a database lock. It's not important how. It is used in the beginning of a large operation, here is how it is used today: public void LargeOperation() { try { ...
2
votes
3answers
99 views

Does this code violate the Single Responsibility Principle?

This is my solution to Project Euler problem 2: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. The class ...
1
vote
1answer
106 views

JavaScript Singletons and Module Pattern [closed]

Is there a preferred way of doing what I describe here. I want to namespace my JavaScript code and use the Singleton Pattern so that only one instance of my JavaScript app exists. I have seen two ...
1
vote
0answers
73 views

Improve the architecture to cache data

I cache the data and use local database in my Windows Phone app. Algorithm is very simple: Get data from DB and show in UI Get data from a web service and show in UI Update data in DB from the web ...
1
vote
2answers
121 views

Which approach for checking for null is preferable?

In my Repository class: public class DeliveryRepository : IDeliveryRepository { private readonly List<Delivery> deliveries = new List<Delivery>(); public Delivery Add(Delivery ...
8
votes
3answers
438 views

Repository/Service Design Pattern

I use the Repository/Service design pattern in my projects and I have found something that might be a bit redundant. Am I writing any unnecessary code? With that in mind, here is my structure: ...
2
votes
1answer
246 views

Builder pattern for Codeigniter ActiveRecord queries

I am using Codeigniter and it's ActiveRecord. I had this idea for a base class that provided a generic getter/setter for doing simple queries on a database. I have a lot of database objects that ...
2
votes
1answer
331 views

Unit of work, Ninject, Repository and WebAPI implementation

after recently getting a bulk of work done on my WebAPI service layer, I thought I'd post some of my working on here for you guys to tear apart, generally, most of it 'feels' mostly okay, but I know ...
2
votes
0answers
107 views

Parallel Job Consumer using TPL

I need to provide a service (either a Windows Service or an Azure Worker Role) which will handle the parallel execution of jobs. These jobs could be anything from importing data to compiling of ...
3
votes
1answer
1k views

Entity Framework using Repository Pattern, Unit of Work and Unity - viable approach?

Using a combination provided from this example and this implementation, I'm creating a solution that decouples the UnitOfWork class from the individual repositories, as they violate the Open-Closed ...
1
vote
0answers
105 views

Basic structure of a simple php REST api

I've read plenty about php OOP design principles and patterns. I can work with classes and inheritance. My issue is with actually using classes for some purpose. In this case, I want to create a ...