Questions tagged [design-patterns]
For questions requesting extra attention to be paid to the usage of design patterns in the code.
1,427
questions
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 ...
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 ...
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:
<...
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 ...
37
votes
2
answers
106k
views
Entity Framework Generic Repository Pattern
Thought 1
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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):
...
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 ...
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 ...
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). ...
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
...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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:...
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 ...
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:
...
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 ...
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.
...
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.
<...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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....
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 ...
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 ...
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 ...
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 ...