35
votes
4answers
28k 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 ...
19
votes
2answers
37k views
19
votes
4answers
3k 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 ...
17
votes
4answers
9k 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 ...
13
votes
3answers
649 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. ...
13
votes
3answers
8k 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: ...
12
votes
2answers
8k 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). ...
11
votes
2answers
134 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 ...
11
votes
1answer
530 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 ...
10
votes
2answers
11k 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 ...
10
votes
3answers
388 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 ...
10
votes
1answer
727 views

UI repetitive code - what pattern to use? [closed]

I have two different windows forms project which contain forms with similar UI/code. For example, I have several forms that have 98% code tha same, the only difference is that one they call different ...
10
votes
1answer
2k views

Multiple Inheritance and Composition with Java and C# (Updated) [closed]

The following article explains the usage of the composition design pattern in environments that do not allow multiple-inheritance of classes. Note: All code examples are written in C#. In Java and ...
9
votes
2answers
365 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 ...
9
votes
2answers
191 views

Decoration Freak, or OCP in action?

I'm writing C# code to read and eventually parse VB6/VBA code modules. I have an interface like this: ...
9
votes
1answer
3k views

What do you think of my EventAggregator implementation in C#?

I was looking for a simple Event Aggregator to use in my app, but I found people get very complicated very quickly, so I thought this was easy enough to write myself. It seems to work, but I was ...
8
votes
5answers
371 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 ...
8
votes
3answers
518 views

Are these endless if statements a bad pattern?

I'm only asking because almost the entire code base I've inherited here, in C# and PHP, looks like this: ...
8
votes
2answers
369 views

3 tier architecture ado.net application

I would like to develop a student management system with repository pattern using ado.net (no EF or MVC). I decided to create the model (business objects) and interfaces as one project ...
8
votes
4answers
317 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, ...
8
votes
3answers
685 views

Is this a good example of the strategy pattern?

I've been reading The Pragmatic Programmer for a few days and I've come across a reference to the strategy pattern. Looked it up in Design Patterns and figured I could refactor a piece of code I'm ...
8
votes
1answer
1k views

best design pattern for refactoring a set of classes that do calculation base on many parameters

I'm refactoring a set of classes which does some price calculations. the calculation is done based on many parameters. The code is : ...
8
votes
3answers
322 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: ...
8
votes
2answers
663 views

Improve a OOP design

I'm having a hard time creating a design (due to my lack of experience). I need a little of help to create the Model. It's a mathematics system. I've created an IProblem interface with a function ...
8
votes
1answer
470 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 ...
7
votes
3answers
758 views

Usage of Decorator pattern in baking program

Is this a good usage of Decorator pattern? I'm trying to use Interfaces instead of Abstract classes. (Component) Interface ...
7
votes
3answers
519 views

Lots of repeating code, trouble refactoring

I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail ...
7
votes
2answers
1k views

Dispose pattern - DisposableObject

I am trying to make an universal implementation of IDisposable (as a base class): ...
7
votes
3answers
1k 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, ...
7
votes
1answer
2k 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 ...
6
votes
7answers
686 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 ...
6
votes
3answers
130 views

Advice on “Factory” Pattern Implementation

I'm refactoring some code around a couple of ASP.NET Web Forms pages and decided to try out a variation of the Abstract Factory pattern of my own design. I need to create an implementer of an abstract ...
6
votes
2answers
218 views

Handle static objects using custom adapter

I have read some articles discussing about why static is bad, some of them refering static as not-testable, non-mockable, has state (non-stateless) and everything else. However I have encountered ...
6
votes
1answer
4k views

Review request: SalesTax problem

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 is ...
6
votes
1answer
342 views

combining 4 CRUD functions into 1?

I have a console application that I'm trying to make with minimal redundant code. I have 4 functions, Create, Read, Update, and Delete. is it possible or practical to combine the four functions ...
6
votes
1answer
102 views

Abstract Factory Pattern C# Example

I am working through more tutorials on Design Patterns and came across the Abstract Factory Pattern. I extended it out a bit (the example that is) and want your opinion: ...
6
votes
1answer
418 views

How can I make this C# code better so it more closely follows DDD principles? Am I using factory correctly?

I've been working on converting some legacy code from T-SQL stored procedures. My aim is to use DDD to make the transition. Below is an attempt to do this. Any comments on how well this is following ...
6
votes
2answers
219 views

Sprite animation for a game

I'm just getting started with XNA and game development in general. I followed these instructions to create a basic game, then this article to get sprite animations working. Now, I'm trying to ...
6
votes
1answer
1k views

How to improve my factory design?

I'm creating a factory design for math problems. The idea which I have is: When the factory initializes, creates in a list some problems (20 initially) If the program wants more than 20, the list ...
5
votes
7answers
347 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 ...
5
votes
3answers
138 views

Abstract factory design for different cars

Is there anything wrong with this? ...
5
votes
2answers
101 views

UnitOfWork, removing abstraction of abstraction (Repository)

I'm creating a small project, but in the past I've used a Repository pattern for it, and it just seemed too bloated. I ended up having repo classes with huge amounts of queries. I'm trying to move ...
5
votes
2answers
680 views

“Fancy-pants” vs “Cowboy” coding

Based on the post I made here: RFC on "Factory" code and its responses, and my (inner) response to those responses, I'm beginning to wonder if it would be just as well to simply switch based ...
5
votes
1answer
71 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): ...
5
votes
1answer
93 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 ...
5
votes
4answers
463 views

How to refactor C# class to meet SOLID priniciple

I need to refactor following class: ...
5
votes
1answer
500 views

How do I make this code unit-testable?

I have a functionality that imports data into a database, based on an Excel workbook and some meta data (both user-supplied). The functionality implements interface ...
5
votes
1answer
2k views

C# Multi level HTML TagBuilder object - Design pattern Review needed

I find the TagBuilder written in C# little poor without the ability to "host" inside it sub tags (as objects not as strings). So I wrote a simple class that inherits TagBuilder and allow to save sub ...
5
votes
3answers
622 views

IEnumerable of classes that implement a given interface at runtime

I am implementing the command pattern in a project that I am working on and I have an interface, ICommandFactory that all of my commands are implementing. When I ...
5
votes
2answers
2k views

MVC Layered Project Structure

We are starting a new web project using C# / MVC 4 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 ...