design-patterns

What is an ObjectMother?

What is an ObjectMother and what are common usage scenarios for this pattern? ...

ORM and layers

Sorry for this point being all over the place here...but I feel like a dog chasing my tail and I'm all confused at this point. I'm trying to see the cleanest way of developing a 3 tiered solution (IL, BL, DL) where the DL is using an ORM to abstract access to a DB. Everywhere I've seen, people use either LinqToSQL or LLBLGen Pro to ge...

Is there an example of the Builder Pattern in the .NET BCL?

Is there an example of the full builder pattern in the .NET base class library? I'm looking for something that has an actual director and multiple concrete builders. ...

What are static factory methods in Java?

My boss always says to use static factory methods, but I'm a beginner and can't understand it. Please help me. What's a "static factory method"? ...

Where should the Accept method of the Visitor Pattern be defined in this case?

Hi, We have services which are either Educational Cess only, Taxable, Non-taxable. Taxes can further be of the following types: Fringe, Sales, Excise, Octroi, Educational Cess, Subsidy, Other Local taxes. We are planning to implement the calculation of taxes using a visitor. What would be the best choice for the Visitable class/interfac...

c# Method looping and control.

Hi guys,I have a method that I would like to run over and over again.I would like to be able to start and stop this process. I have been using this pattern for some socket work and I am wondering what improvements I can make? public delegate void VoidMethod(); public class MethodLooper { private VoidMethod methodToLoop; privat...

How should I refactor this design.

How should I refactor this design? class Service : IChargeable, IExtendable<br /> { } interface IChargeable { decimal? ChargeableAmount { get; } } interface IExtendable { bool IsExtendable { get; } } class DayService : Service { } class NightService : Service { } class TwentFourService : Service { } The probl...

Using template parameter within a second template (STL container)

I'm a noob experimenting with templates and design patterns and would like to create an iterator pattern using a template argument ITEM. However, my private member var is a STL container that is itself a template, so how can I 'sync' the template argument of the STL container to that used by the class template? Here is the actual cla...

All About Exceptions: What to do and Where to log?

My question actually comes in two parts hence the ambiguous title. Part One As far as I'm aware, you should never swallow an exception. Not even logging it and forgetting about. In general cases, I try to solve an exception and retry the code - for example, let's say I get a FileNotFound exception. I prompt the user to check the file ...

Simple java message dispatching system

I'm working on a little Java game in which all sorts of events can happen. There are at least a couple of dozen basic events that various event handlers may be interested in. There are also several places in the code where these events might be triggered. Rather than forcing the event listeners to know which class they need to registe...

3 layer architechture and little details like dropdown lists

So I am refactoring a little application as an example to get more practice. The purpose of the application (let's say) is to collect the data from a "sign up new user" form, save it in the database. The only limitation I have is I have to use a special custom Data Access class which communicates directly with the database and returns th...

How to stop Pages becomming too bloated in webforms

I have an ASP.net webforms app that connects to a web service, All the functionality is on one page that has lots of difference states and I use a multi view to display the correct html depending on the current state. The problem is the page is huge and unweildly. The code behind isn't so bad but the aspx page is just out of control. I...

OO Design Pattern on a Package/Assembly/Namespace level?

I was looking at this question and I wondered to myself are there any design patterns/rules of thumb that you can use when breaking up your project into packages/assemblies. I usually don't seem to have any issues with this as I tend to just break stuff up into packages/assemblies such that each does as little as possible that is releva...

How to use log4net with Dependency Injection

I'm trying to figure out what the right patter and usage of log4net is with a dependency injection framework. Log4Net uses the ILog interface but requires me to call LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType) in each class or method where I need to log information. This seems to go against IoC prin...

public class member visible to descendents

I have been getting a lot of traction from a builder pattern as a public class member of another class: public class Part { public class Builder { public string Name { get; set; } public int Type { get; set; } public Part Build() { return new Part(Name, Type); } } pro...

Static Method or OO Alternative?

Lets say that one has a class like Person that has associated with it some default settings implemented in a Setting class. Those settings might be things like "Default Title" or "First Name Required". Correspondingly, other classes like an Address class might also have some default settings. The Setting class persists each setting in...

Is there a recognized pattern for useless objects that implement an interface?

For example, (although it's not an interface) the Stream class in .NET has an implementation provided by Stream.Null which simply discards the data. PowerShell has Out-Null. In applications I've developed, I've often found it useful to implement an interface IFoo with a default implementation NullFoo or similar when it is preferable to ...

What are the .net reference implementations of the Unit of Work pattern ?

Possible Duplicates: unit-of-work-pattern-in-net rhinocommons-unitofwork-question-with-asp-net-mvc The Unit of Work pattern is a way to keep in a context to track all the actions on your domain and to apply them all at once when your - possibly - complex logic is done. When used with an ORM (NHibernate for instance), it is cons...

One SQL query, or many in a loop?

I need to pull several rows from a table and process them in two ways: aggregated on a key row-by-row, sorted by the same key The table looks roughly like this: table ( key, string_data, numeric_data ) So I'm looking at two approaches to the function I'm writing. The first would pull the aggregate data with one query, an...

Is there a design pattern that deals with callback mechanism?

Is there a design pattern that deals with callback mechanism? ...