Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [design-patterns]

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

Filter by
Sorted by
Tagged with
14
votes
7answers
4k views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the ...
16
votes
2answers
3k views

Down the rabbit hole with MVP

Following-up on this post where I implemented a Repository Pattern in vba to abstract ADODB and enable testing my Excel app without hitting a database backend; curious about how far vba would let me ...
1
vote
0answers
167 views

My included in every script file - follow-up -1

In this particular question, I need the reviewers help to judge my understanding to MVC and OOP as it was my biggest problem in my original question a month ago. I included in the question the contact ...
4
votes
4answers
500 views

Creating an array that loops out on the frontend - Don't Repeat Yourself?

Entire Code Here Don't repeat yourself I know of the "Don't repeat yourself". Still it's getting messy in some places. The code below contains three blocks of code. They are similar in some ways ...
61
votes
4answers
55k views

EF Code First with Repository, UnitOfWork and DbContextFactory

I am about to >explode< :) due to amount of reading on this subject... My head hurts, and I need some honest opinions... There is a similar question/review that I noticed, but I believe my approach ...
21
votes
1answer
11k views

Strategy design pattern with various duck type classes

I've recently picked up the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Unfortunately, the code examples in this book are in Java. I'm not ...
15
votes
4answers
1k 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. ...
20
votes
3answers
2k views

How to Train Your Dragon

I started out practicing on implementing the builder pattern and somehow ended it up with this 2 hours later. It isn't really much, but it works and I'm hoping review should bring about a lot of ...
23
votes
6answers
2k views

A Library Class : Point

I am trying to create a library of my own which contains (among others), a class called Point. As the name suggests, it is intended to encapsulate a point ...
8
votes
3answers
37k 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 ...
7
votes
1answer
6k views

Hypothetical SalesTax challenge

I have a small solution to the following hypothetical problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty ...
4
votes
3answers
1k views

Mixin, @extend or (silent) class?

I am struggling with the basic concepts of SASS. I have a page that has multiple section, all of them are sharing properties like width, ...
3
votes
2answers
1k views

Create database connection and run the insert, delete, update queries class

Recently while developing our demo project I had to a write a lot of repetitive code for executing the database queries (insert, update, delete). So, I have put all the repetitive code into a class ...
4
votes
3answers
1k 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 ...
2
votes
2answers
77 views

Logger adapter with a configurable chain of responsibility of middlewares

I use my own logger adapter that collects data into a dictionary: public class Log : Dictionary<string, object> { } This is really all I have. I then pass ...
1
vote
1answer
606 views

Refactoring conditional statements among different classes

I wonder there is any method of refactoring nested condition. It's just the same content with different contents and different classes which looks bad. I really want to reform this code which looks ...
7
votes
1answer
323 views

Model simulation using Java annotations

A couple of days ago I posted my code that models systems made up of moving parts. I got several great tips and ideas and here is my latest version. My actions are now methods annotated with @Action (...
7
votes
0answers
314 views

STTCL FSM framework based on the GoF State Pattern, Part I: The basic interfaces

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
6
votes
3answers
4k views

Building tree structure based on flat objects

You can find here a Follow-up question Description A List<UnrelatedObects> is returned by a 3rd party webservice, which will then be transformed to a ...
6
votes
5answers
762 views

DP solution to min triangle path

I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
2
votes
0answers
50 views

STTCL FSM framework based on the GoF State Pattern, Part II: Abstraction of asynchronous/concurrency features

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
1
vote
1answer
337 views

How to add a random feature for a factory design

I'm creating a factory design for math problems. The purpose of the factory is: The problems must be generated with a certain difficulty (or level). To do this, I'...
1
vote
0answers
89 views

Watch that uses the abstract factory design pattern

I have wrote code for a Watch that utilizes the abstract design pattern and would like to get some feedback on the code, be as harsh as you can. Also, I would like ...
69
votes
6answers
192k views

Design a chess game using object-oriented principles

I would like to know if my approach is correct and how could it could be improved? Also, is there a way to get rid of the relation between the Piece and the ...
45
votes
3answers
91k 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: <...
38
votes
2answers
3k views

KISS my… unit of work

I've seen many, many UoW+Repository implementations. Whenever one was built on top of Entity Framework, I'd cringe at the added complexity. Sure the complexity buys you (sometimes) full decoupling ...
20
votes
2answers
36k 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 ...
13
votes
2answers
10k 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 ...
19
votes
2answers
13k views

C++ Observer design pattern implementation

I'm using the Observer design pattern in order to manage events in the game I'm currently developing. I based myself on the implementation demonstrated here but improved it in order to ease its use. ...
3
votes
1answer
3k views

Is this a workable UnitOfWork with Repository pattern design?

I am building a web app with using UOW and Repository pattern. I have seen many different samples and found each one to be different, so not sure which is the correct way to go. I have a basic ...
4
votes
1answer
6k views

Repository pattern with plain old PHP object

I've been reading a lot about repository patterns these days. At first, the pattern seemed easy. Most of the examples I read over the web use an ORM like below. ...
15
votes
3answers
2k views

RPG Character Builder

This implements a builder pattern for RPG game characters. Is this a valid builder pattern implementation? There are 3 characters: Paladin, Wizard and Elfo. There are 3 items: Potion, Sword, Arch. <...
14
votes
1answer
2k views

Ambient Context

What do you think about this way to make logging available across the application without passing log object around? Let’s say we have something which allows us to ...
14
votes
2answers
1k views

YARPI: Yet Another Repository Pattern Implementation

Following-up on this post, I wanted to be able to put a copy of that Excel workbook on a USB key and take it home to keep working on the code a bit (there's more than just one or two tables to ...
11
votes
1answer
2k views

Problem: Traffic Flow

I have the following task: The Shallow Alto city council has organized a special committee to review the traffic situation in the city. Despite the fact that there is nothing whatsoever to do ...
7
votes
1answer
168 views

Cascading a property for a game

I'm trying to write a simple game. I have an Entity object, that has a list of Sprite objects. Each ...
6
votes
2answers
538 views

System for registering people

For a small administrative program, I have to be able to register people and their data. But, files are sometimes created through a phone call "on the fly" and then later certain data is added to the ...
12
votes
2answers
3k 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 ...
10
votes
3answers
643 views

Is this correct factory method pattern?

I know that there are many similar questions, but I don't understand most of those questions because I'm not sure if I know what a factory method pattern is. So, after reading many examples over the ...
9
votes
5answers
15k 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? ...
8
votes
1answer
171 views

Class containers, filtering and coding practices

Context Usually, when I have to deal with a collection of items (especially objects) I tent to create a container class for that collection (wrapper?). What I mean by that is: when I have to handle ...
8
votes
4answers
2k views

A new type of builder pattern

The fact is that I wanted to apply the builder pattern. But this could not be achieved, since I could not create an instance of the class with an empty constructor - this is dangerous. The goal is to ...
6
votes
1answer
2k 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 ...
4
votes
1answer
548 views

How to convert my classes to Dependency injection?

I am still learning to develop my skills in OOP. It uses a combination of the factory and its real singletons? As I did more research, I have realized this design pattern is bad because of global ...
3
votes
1answer
735 views

Parallel Job Consumer

Edit: A second iteration of this problem here. 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 ...
3
votes
2answers
13k 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 ...
3
votes
3answers
300 views

Refactoring a class hierarchy to remove subclasses

I have the following class inheritances hierarchy: First the abstract parent class: ...
11
votes
4answers
3k views

Composite and Visitor patterns for tree-based survey functionality in C#

I have written some survey functionality for a project. Basically, a generic survey form that can be composed of sections and questions. I have a Survey class, <...
11
votes
3answers
213 views

OOCSS: Is this broken down too much?

Philosophical question: How far should I break down my objects? Inuit.css and Bootstrap have islands, islets, wells, grayboxes, and other objects that have repeating properties. I don't think it was ...
9
votes
1answer
194 views

Injecting stereotypical role implementations by IoC container

AN UPDATED VERSION with GitHub link is avalable HERE. I am trying to define a plug and play architecture which leverages stereotypical role implementations (Validator, Reader, Writer, Logger, Query, ...