design-patterns

Software Architecture for developing apps that run on Multiple platforms

A variety of apps out there, like Firefox, Fring, Skype run on a variety of platforms. How do they manage their code? Do they have different UI for different platforms? As in, Firefox have to use Cocoa on Mac, WinForms or equivalent on Windows, QT equivalent on Linux. How is it possible for the same source code to show diff UI just by co...

Unit of Work Design Pattern

Does anyone have any good links about a practical example of Unit of Work pattern with LINQ to SQL ...

Validation and in Service Layer or Business Objects?

Martin Fowler suggests using a service layer as a boundary between the domain model and and "Data Loaders". However, Rockford Lhotka suggests building validation into the business object itself and this is exactly what CSLA.NET does. The benefits of abstracting this into a service layer is obviously that your service layer can coordinat...

How do you design a web application that needs to be customized for each new client?

I've been tasked with re-writing a fairly large web application for a company. This application provides certain financial/risk analysis to 3 clients that we currently have. The huge issue around this app is each client is different and has slightly different data. They all log into the same website but after that their experience ca...

MVVM Inheritance With View Models

I am wondering about how to approach inheritance with View Models in the MVVM pattern. In my application I have a Data Model that resembles the following: class CustomObject { public string Title { get; set; } } class CustomItem : CustomObject { public string Description { get; set; } } class CustomProduct : CustomItem { ...

What are some situations in which the Decorator Pattern solves the problem really well?

I think a classic example is that the Window class can have a Border decorator and a ScrollBar decorator in the GoF book. What are some situations you think, know of, in which the Decorator Pattern solves the problem really well? ...

Is the Decorator Pattern too much for implementing a coffee ordering system?

Update: Since we usually say, "the situation will determine if any Design Pattern is a good fit for the job"... will a coffee ordering system in real life be solved using the Decorator Pattern? Is the Decorator Pattern too much for implementing a coffee ordering system? The Head First Design Patterns book use it as an example, but I t...

How important are Design Patterns really?

How important are Design Patterns really? I think the earlier generation of programmers didn't use Design Patterns that much (people who graduated in the 80s and before mid 90s). Do the recent graduate know it in general and use it a lot more? If you are interested, I also made a survery and you can view it here: http://www.surveym...

oo question - mixing controller logic and business logic

I'm not sure if I'm using "standard" terms, but this is a basic OO question I'm trying to resolve. I'm coding a windows form. I don't want logic in the form event handler, so I just make a call to a custom object from there. At the custom object, there are two sets of logic. The "controller" logic, which decides what needs to get ...

Command pattern without virtual functions (C++)

For performance reasons, I am using the the Curiously Reoccuring Template Pattern to avoid virtual functions. I have lots of small commands which execute millions of times. I am trying to fit this into the Command Pattern. I want to add tons of commands to a queue, and then iterate through them executing each one by one. Each Command...

Is it wrong to use the decorator pattern like this?

I've noticed that on all the examples that illustrate the decorator pattern, there is a base class/interface and there is a decorator class that inherits/implements it, after which, all the decorated classes extend the decorator class. Something along the following lines : Interface Window > WindowDecorator > WindowDecorator > VerticalS...

Should I use exceptions in C# to enforce base class compatibility?

On one hand, I'm told that exceptions in C# are 'expensive', but on the other, I'm stuck on how to implement this. My problem is this: I'm making a Stream derivitive, that wraps a NetworkStream. Now, the problem I'm facing is this: Read(byte[] buffer, int offset, int count). From the Stream docs for the function: Returns: ... o...

C# Linq: Can you merge DataContexts?

Say I have one database, and this database has a set of tables that are general to all Clients and some tables that are specific to certain clients. Now what I have in mind is creating a primary DataContext that includes only the tables that are general to all the clients, and then create separate DataContexts that contain only the tabl...

Service Design (WCF, ASMX, SOA)

Soliciting feedback/thoughts on a pattern or best practice to address a situation that I have seen a few times over the years, yet I haven't found any one solution that addresses it the way I'd like. Here is the background. Company has 3 applications supporting 3 separate "lines of business" that are very much related to each other. Tw...

C#: Instantiate an object with a runtime-determined type

I'm in a situation where I'd like to instantiate an object of a type that will be determined at runtime. I also need to perform an explicit cast to that type. Something like: static void castTest(myEnum val) { //Call a native function that returns a pointer to a structure IntPtr = someNativeFunction(..params..); //determi...

C# Strategy Design Pattern by Delegate vs OOP

Hi, I wonder what's the pros/cons of using delegate vs OOP when implementing strategy design pattern? Which one do you recommend to use? or what kind of problem does delegate solve? and why should we use OOP if OOP is better? Thanks! -tep ...

Alternative to the visitor pattern?

I am looking for an alternative to the visitor pattern. Let me just focus on a couple of pertinent aspects of the pattern, while skipping over unimportant details. I'll use a Shape example (sorry!): You have a hierarchy of objects that implement the IShape interface You have a number of global operations that are to be performed on all...

Best Way To Deliver A Static HashTable c#

Hi all! I have the following as an example: public enum HttpRequestHeader { Accept, AcceptCharset } public static class HTTP { public static Hashtable HttpRequestHeaderString { get { Hashtable returnHashtable = new Hashtable(); returnHashtable.Add(HttpRequestHeader.Accept,"Accept"); returnHashtable.Ad...

How do I collect statistical information on application usage in ASP.NET MVC?

I'd like to collect statistical information, such as PageViews, Number of comments for each user, etc. I've thought about using the observer pattern. How would I implement this in ASP.NET MVC? ...

Can you explain the Context design pattern a bit?

I've started to read about the Context design pattern. Here's what I understood from the text : you have a map containing all your variables you pass it around to whoever needs it, so that you won't have to send all the variables as method parameters Did I "get" it? ...