design-patterns

State Machine Frameworks for .NET

We have a system at my work that is basically a message-driven state machine. It takes in a variety of types of messages, looks up some context/state based on the message, then decides what to do, based on the message and the current state. Normally the result is a message being sent out of the system. Are there any good open-source f...

Should collections also be responsible for creating objects? (Single Responsibility Pattern)

Should a collection of objects also be responsible for creating new objects? Let me explain. I have two classes, PhoneCall and PhoneCallList. PhoneCallList is a collection of PhoneCall objects. Our architect and I are at odds on how to go about creating new PhoneCall objects. Currently the PhoneCall object has a method called Crea...

Logic is now Polymorphism instead of Switch, but what about constructing?

This question is specifically regarding C#, but I am also interested in answers for C++ and Java (or even other languages if they've got something cool). I am replacing switch statements with polymorphism in a "C using C# syntax" code I've inherited. I've been puzzling over the best way to create these objects. I have two fall-back meth...

Are staging tables / staging databases an anti-pattern?

Are staging tables an anti-pattern that is used when rpc (such as Java RMI or some kind of Web Service call) or messaging queue (such as JMS) would be a better solution, or are there problems better served by staging tables? To clarify: By staging tables I mean those cases where records are appended to a table or tables by a process wh...

Object's state in the Template method design pattern

Here is an implementation example of the algorigthm in the base absctract class from http://sourcemaking.com/design_patterns/template_method/php public final function showBookTitleInfo($book_in) { $title = $book_in->getTitle(); $author = $book_in->getAuthor(); $processedTitle = $this->processTitle($title); $processedAuth...

Design Pattern for Java: Does this look familiar to anyone?

In my application, I have the following recurring pattern where I get the feeling that this is an incomplete or warped version of some common pattern that I'm not aware of. In my implementation, I can't seem to find a good way to implement a particular operation, as described below. A collection of objects, let's call them "sources", pr...

What is the best way to declare a global variable?

In C++, say you want to declare a global variable to be used by many. How do you do it? I commonly use declare and define in cpp file, and then use extern in other cpp file (and not headers). I don't like this approach, and I am considering something along these lines: In a header file: some_file.h Class MYGlobalClass { }; MyGl...

Design problem: Get child object type information avoiding if statements in presentation layer

I have a customer hierarchy like so: abstract class Customer { public virtual string Name { get; set; } } class HighValueCustomer : Customer { public virtual int MaxSpending { get; set; } } class SpecialCustomer : Customer { public virtual string Award { get; set; } } When I retrieve a Customer, I would like to show on ...

How do you make one generic select method for your DAL ?

Scenario You have an Assembly for Data Transfer Objects containing 10 classes that exactly represent 10 tables in your database. You generate / build a DAL layer that has methods like - DTOForTable1[] GetDataFromTable1(); DTOForTable2[] GetDataFromTable2(); and so on.... Question How do I make a method that hides the numerous...

"Handler" pattern?

I've come across a design pattern that's been referred to as a "Handler Pattern," but I can't find any real references to this pattern anywhere. It's basically just a one-method interface that allows you to easily extend the functionality on the back-end without making clients recompile. Might be useful for a web-service that has to ha...

Pattern name for projecting DAL specific classes (such as LINQ to SQL classes) to POCO's

I was studying the Oxite project on Codeplex. It has repository interfaces, and an implementation using LINQ to SQL. The LINQ to SQL results are projected to POCO objects in the repository implementations. It looks something like: public IQueryable<Post> GetPosts() { return projectPosts(excludeNotYetPublished(getPostsQuery(siteID)))...

Downloadable code examples for OOP design-patterns in .NET?

Does anyone know of some good downloadable visual studio solution files that explain all the GOF design-patterns (and their variants if possible) in .NET (C# preferred)? ...

What's the best way to target both WPF and Web apps?

We are currently designing a business application that has two primary requirements for it's UI: 1) run on the Desktop (WPF) for enterprise users to provide a rich user interface, interoperate with other applications, access the filesystem, work offline, work with special local hardware, etc. 2) run on ASP.NET/Ajax to provide several c...

Preventing the browser from showing the query re-submit dialog on refresh

When the user select an item from a dropdownlist and presses a button, my application shows a list of data manually binded and filtered according the selected value. If the user presses the Refresh button of the browser, it asks for confirmation whether the user is sure they want to submmit the query again. I don't want the browser asks...

Best "pattern" for Data Access Layer to Business Object

I'm trying to figure out the cleanest way to do this. Currently I have a customer object: public class Customer { public int Id {get;set;} public string name {get;set;} public List<Email> emailCollection {get;set} public Customer(int id) { this.emailCollection = getEmails(id); } } Then my Email object ...

Data Binding as a design pattern

Where can I find a discussion of the Binding in a way similar to GoF? ...

Mediator design pattern ~= Transaction Script?

It looks like the more Mediators in a design, the less quality the design has. Because it means more is done in procedural scripts inside Mediators, and less in OOP.. How do you think? It reminds mi Transaction Script vs Domain Model contrast from Martin Flower books. I just catched myself on writing a Mediator object that connects 4 o...

Local vs. Centralized Processing

Hi Everyone, I work at a company with a large SAP investment, and we also have dozens of large .Net systems (mostly internally for engineering systems), and Java platforms (mostly for external web applications). As such, we have large development shops on ABAP, C#, and JEE. We have over 20 major facilities distributed over very large d...

MVVM - what should contain what... what should create what

I'm having a right barney getting my head around how everything fits together using the MVVM pattern. It all seems quite simple in practice but trying to implement it I seem to be breaking various other rules that I try to code by. Just as a side note, I'm trying to implement the pattern using Flex, not Silverlight or WPF, so if anyone...

How to determine which controller an action belongs in?

I have two models: releases have many elements, and elements belong to releases. The action I wish to define imports all elements (making copies of them all) from one release into another release. How do I determine if this action belongs as a member action on the releases controller, or a collection action on the elements controller?...