Skip to main content

Questions tagged [design-patterns]

For questions requesting extra attention to be paid to the usage of design patterns in the code.

Filter by
Sorted by
Tagged with
80 votes
6 answers
233k 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 ...
SummerCode's user avatar
69 votes
4 answers
59k 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 ...
zam6ak's user avatar
  • 801
51 votes
3 answers
109k 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: <...
user avatar
38 votes
2 answers
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 ...
Mathieu Guindon's user avatar
37 votes
2 answers
106k views

Entity Framework Generic Repository Pattern

Thought 1 ...
ashutosh raina's user avatar
33 votes
5 answers
1k views

I have a problem ...factory

I'm creating a system to generate math problems. As you know in mathematics, there are several different kinds of problems: Binary problems, fractions, decimals, comparating two numbers, etc. I'm ...
Darf Zon's user avatar
  • 561
29 votes
2 answers
91k views

Implementing factory design pattern with generics

In this new project I'm working on I need to create objects on runtime by data from the DB, right now I have two groups of classes, each group implementing a different interface. I started working on ...
Mithir's user avatar
  • 403
28 votes
2 answers
16k views

Reusable Unit Of Work Interface / Factory

Given my IUnitOfWork interface using System; public interface IUnitOfWork : IDisposable { void Commit(); } I then ...
Issa Fram's user avatar
  • 409
27 votes
3 answers
2k views

How is my CMS design? Any security, design, or other issues?

I am trying to learn PHP in depth by creating this personal CMS. I try to utilize OOP concepts and do best I can... The way I am trying to design this CMS is to keep including 'modules' within a page ...
HelpNeeder's user avatar
26 votes
4 answers
2k views

Law of Demeter and data models?

Inspired by this question, but hopefully not a duplicate. I understand that the Law of Demeter is very useful in case of services interacting with other services, for example it's much easier to mock ...
Bolo's user avatar
  • 588
25 votes
6 answers
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 ...
Hungry Blue Dev's user avatar
25 votes
1 answer
5k views

A Pong Game using C++

I wrote a simple, 2-player Pong game for a Udacity Nanodegree in C++. The program has the following class structure (relatively new to UML so any tips on here would be very much welcome too): ...
Eon's user avatar
  • 351
25 votes
4 answers
14k views

Interface for unit of work pattern and repository pattern

I'm trying to design a well defined yet simple interface for the unit of work and repository patterns. My UoW's are exposed to services and services then "get repositories" that it needs to query. I ...
TheCloudlessSky's user avatar
24 votes
1 answer
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 ...
PythonJin's user avatar
  • 485
24 votes
1 answer
17k views

Generic repository and unit of work code

I am writing a WPF application that needs to access information from a database (I am currently using Entity Framework code first, so data access is via DbContext). ...
Benjamin's user avatar
  • 443
23 votes
4 answers
28k views

Simple builder pattern implementation for building immutable objects

This is a builder pattern implementation to build immutable Person objects: Person class ...
Levent Divilioglu's user avatar
23 votes
5 answers
22k views

Best way to pass parameters to Factory class?

So I have a series of objects, which I will call Impl1, Impl2, and Impl3. They each implement an interface, called IImpl. I have a Factory class who's task is to retrieve the ImplX which is ...
GWLlosa's user avatar
  • 451
23 votes
2 answers
15k 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 ...
Chafic's user avatar
  • 585
21 votes
2 answers
4k views

Builder Pattern for Car class

I have some experience in Java. I am reading Effective Java by Joshua Bloch, the book talks about Builder pattern which I was unaware of. So,I have assembled a quick example of what I think builder ...
n00b's user avatar
  • 313
21 votes
3 answers
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 ...
Legato's user avatar
  • 9,829
21 votes
2 answers
15k 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. ...
AntoineB's user avatar
  • 313
21 votes
2 answers
39k 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 ...
Aseem Bansal's user avatar
  • 2,269
20 votes
3 answers
40k views

MVC Layered Project Structure

We are starting a new web project using C# / MVC4 and Entity Framework 5 for data access. I've decided to go with an n-layered approach for the structure of the project and I would like some feedback ...
zday's user avatar
  • 301
19 votes
2 answers
4k 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 ...
Mathieu Guindon's user avatar
18 votes
1 answer
33k views

Following Repository Pattern properly

I am new to learning Repository Pattern. I am developing a site in MVC 4 (I'm new to it as well). The way I am using Repository pattern as follows: I created ...
Aamir's user avatar
  • 333
18 votes
2 answers
3k views

A KenKen puzzle/solver in Python

I've written a simple KenKen puzzle/solver in Python. I'd love some feedback on the design of the puzzle, as well as the architecture for the solver. To model the puzzle, I have the following classes:...
user138440's user avatar
17 votes
7 answers
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 ...
user2040026's user avatar
17 votes
2 answers
2k views

Singleton Design Pattern implementation in a not traditional way

For implementing Singleton we can use Traditional way like this Article, but i think that to write it in another way: ...
pmn's user avatar
  • 273
17 votes
2 answers
5k views

Understanding the MVVM concepts and validation of my code

I have been learning MVVM concepts and trying to implement it in my new project. I want to validate my work that I have been doing these past days. I want to know if I follow correctly the MVVM ...
Sam's user avatar
  • 171
16 votes
4 answers
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. ...
Evan L's user avatar
  • 291
16 votes
3 answers
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. <...
Edson Alcalá's user avatar
15 votes
4 answers
373 views

More German overengineering™ - Class mappings and factories

Goals: So the plan was simple: Provide a factory to instantiate implementations of a certain interface (ModelConverter<T>), depending on what model-class you ...
Vogel612's user avatar
  • 25.3k
15 votes
1 answer
22k views

Simple example of N-Tier, entity framework, unit of work, repository, business logic layer

I've been studying C# for about 6 months and am trying to make a simple example for an n-tier application. I want to learn to do things in the most proper and professional way. This example uses a ...
David's user avatar
  • 251
15 votes
2 answers
40k views

Unit of work + repository + service layer with dependency injection

I am designing a web application and a windows service and want to use the unit of work + repository layer in conjunction with a service layer, and I am having some trouble putting it all together so ...
Guillermo Gomez's user avatar
15 votes
1 answer
773 views

Simple dictionary storing/viewing application

A TreeView on the left which just displays a list of files saved by the application. A DataGridViewon the right to display data ...
Anthony's user avatar
  • 503
15 votes
1 answer
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 ...
Dmitry Nogin's user avatar
  • 6,131
14 votes
3 answers
508 views

Building unusual IComparer<T> from expressions

I've needed a couple of very special comparers recenty and didn't want to implement each one of them every time so I created a builder and a couple of supporting classes that do that for me. Example ...
t3chb0t's user avatar
  • 44.3k
14 votes
6 answers
2k views

C# Method Chaining for Email

I have been looking into stuff like method chaining, Cascade-Lambda pattern etc. I have created a class which seems to work fine. However, I just wanted to confirm if this is the best way and the ...
Praneet Nadkar's user avatar
14 votes
4 answers
2k views

Making a web service call based on a type of request

I have my code which makes a web service call based on a type of request: ...
Simsons's user avatar
  • 723
14 votes
2 answers
2k 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 ...
Mathieu Guindon's user avatar
14 votes
3 answers
19k 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 have ...
James Law's user avatar
  • 497
13 votes
5 answers
13k views

Is this Repository Design Pattern Valid and efficient?

I am using Dapper ORM in my Data access Layer, but I think analysis of the code below doesn't depend upon any specific ORM. What should be the single common place throughout the entire Data Access ...
Abhi's user avatar
  • 231
13 votes
1 answer
13k views

Business with dbcontext and static class

Many speak of using dependency injection. I do not use repository. The entity framework is uow/repository. What is wrong with using static class like the one below? My context is a new instance per ...
Marcos's user avatar
  • 139
13 votes
2 answers
11k 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 ...
1110's user avatar
  • 217
13 votes
2 answers
10k views

Binary Search Tree Data Structure Implementation in C++11 using Smart Pointers

This implementation is part of my open source project forest. I wrote the following header file to implement a binary search tree data structure that supports the following operations: Insert Search ...
user avatar
13 votes
1 answer
5k views

Generic Converter framework

I find myself frequently converting between formats, so I have come up with the following conversion framework. The converter interface surfaces a method to convert from a source type to a target type....
Hawk's user avatar
  • 233
12 votes
4 answers
878 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 ...
mawburn's user avatar
  • 275
12 votes
4 answers
1k views

Decision Table for the Movement AI in a Game

I posted a question on Stack Overflow about how to implement Decision Tables in Objective-C after reading about them for the first time in chapter 18 of Code Complete. Nobody provided an answer, so ...
bazola's user avatar
  • 8,569
12 votes
3 answers
79k views

Validate and import data from an Excel file

I have recently designed a module which will do bulk upload for different contents. Basically the user will upload an Excel file, I will have to read and validate headers of excel then each value of ...
VIckyb's user avatar
  • 665
12 votes
5 answers
9k views

Optimizing boolean checking method

I have written a method that checks if n number of true booleans are present in a ...
Hungry Blue Dev's user avatar

1
2 3 4 5
29