design-patterns

What is your favourite asychronous pattern?

I'm currently trying to get my head around the CCR as a Asynchronous programming model. In the past i've used the standard begin/end methods. I primary develop in VB.net and have been looking with longing at the Yield/Enumerator tricks. What is your favourite asychronous pattern? ...

Keeping an object graph consistent

I have a situation where an object A has a reference to object B. B also has a reference back to A. For the sake of simplicity, let's say that A and B are of the same type. How do I ensure that when I update the reference on A, that the update will be reflected on B as well (and vice versa)? An example of an interface of such a type:...

Pure Virtual Method VS. Function Pointer

Hey all, Recently I've been designing a Thread class library, I've made a Thread abstract class like the following: class Thread { public: run() { /*start the thread*/ } kill() { /*stop the thread*/ } protected: virtual int doOperation(unsigned int, void *) = 0; }; Real thread classes would inherit this abstract class and ...

What are some good resources for learning network programming?

I recently started attending two classes in school that focus on networking, one regarding distributed systems and another regarding computer networks in general. After completing the first labs for the two classes, I now have a pretty good understand of network protocol and socket concepts with both C and Java. Now I'm trying to move b...

ASP.Net -- How to effectively use design patterns without over-engineering!

I'd appreciate people's thoughts on a dilemma I've been struggling with ever since ASP.Net came out. In classic ASP, the layers of code were minimal. The ASP page contained HTML and script combined. The COM components contained business logic and DAO infrastrcuture. The asp pages themselves were messy, but everything was in one place...

How would you use design patterns to educate and share design experiences?

Hi all, I work in an environment where scientists and programmers work together to create and maintain scientific simulation software. The software exists for 20+ years, and shows its C/procedural programming heritage, although the intent is to improve object orientation in the design. The scientists have been involved in the developm...

Large Switch statements: Bad OOP?

I've always been of the opinion that large switch statements are a symptom of bad OOP design. In the past, i've read articles that discuss this topic and they have provided altnerative OOP based approaches, typically based on polymorphism to instantiate the right object to handle the case. I'm now in a situation that has a monsterous s...

The Decorator Design Pattern

I am just starting to learn design patterns and I have two questions related to the Decorator... I was wondering why the decorator pattern suggests that the decorator implement all public methods of the component of which it decorates? Can't the decorator class just be used to provide the additional behaviors, and then the concrete com...

Examples of Patterns that have real world examples

Pretty much every resource I've seen on design patterns always have examples like Dog, Animal, PizzaFactory, AbstractPizzaFactory and others. I'm looking for good resource such as Head First Design Patterns with actual real-world patterns that will make the "understanding-process" slightly easier. In my opinion the factory pattern exam...

In the Model View Presenter pattern, can a presenter take and use two different view interfaces at the same time?

I'm curious about the situation where you have a user control that you want to reuse throughout an application, but you also have a page or other control that also needs a presenter. So say I have an upload view and control public partial class UploadControlView : System.Web.UI.UserControl, IUploadView but I also have a page view ...

Interesting API Design/Pattern Question

I am re-designing part of our internal ORM tool, and I want to expose Field (a class that represents a field in the database, like CustomerFirstName) directly to the end-developer. So that was easy enough to accomplish, however the API got a little ugly because this Field class was previously used internally and is too open. For instanc...

How to effectively use DTO objects (Data Transfer Objects)?

What is the best way to implement DTOs? My understanding is that they are one way to transfer data between objects. For example, in an ASP.Net app, you might use a DTO to send data from the code-behind to the business logic layer component. What about other options, like just sending the data as method parameters? (Would this be easi...

AntFarm anti-pattern -- strategies to avoid, antidotes to help heal from

I'm working on a 10 page web site with a database back-end. There are 500+ objects in use, trying to implement the MVP pattern in ASP.Net. I'm tracing the code-execution from a single-page, my finger has been on F-11 in Visual Studio for about 40 minutes, there seems to be no end, possibly 1000+ method calls for one web page! If it wa...

Factory pattern in C#: How to ensure an object instance can only be created by a factory class?

Recently I've been thinking about securing some of my code. I'm curious how one could make sure an object can never be created directly, but only via some method of a factory class. Let us say I have some "business object" class and I want to make sure any instance of this class will have a valid internal state. In order to achieve this ...

need wcf and wpf application source code for beginer

Hi, I am beginner for .net 3.5, have to work on app where I need to build desktop version as well as web version for selected modules like reporting. I think WCF will help me out to create a base from where I could call functions in both(desktop as well as web ) Please let me know the any available source code sample projects to go thr...

If-less code: is it just an intellectual challenge or is it concretely useful?

A friend of mine is talking about these design techniques regarding state transitions of an object (he's a Java guru, btw), performed without having a boolean myState member, but rather declaring the myState member as an object that implements the same interface of the "owner" one. Ok, I've been too much cryptic, so you can find the dis...

How to store many prices for a product in a flexible way?

I want to build a shop in which the products have a little wizard through which the price then is determined. In this case I'm talking about printing products. So for (a little) example when you come to the shop and want to print a business card, you get to decide if you want to print black and white or in color, if you want to choose t...

Is it worth using 3-tier architecture for small(ish) applications

I'm working on a relatively small asp.net web application and am wondering if there is really a need to employ full n-tier architecture. For an idea of size; there are about 20 database tables. In the past I have used a 2-tier approach where business logic and data access are grouped together into a single class library with was an asp...

What objects should you return from the data access layer to the business layer an n-tier system

If you have, for example, a database table called Person (ID,Name etc) what kind of object should the data access tier return to the business tier? I'm thinking something like this: //data access tier public class DataAccess{ public interface IPerson{ int ID{ get; set; } string Name{ get; set; } } internal class P...

Enumeration and constants

Is there better way than declare enumeration as public enum DepthNumberSize { Bit1 = 1, Bit4 = 4, Bit8 = 8, Bit16 = 16, Bit32 = 32 } and every time when operations with related data chunk performed switch statements are used, like: switch(size) { case DepthNumberSize.Bit1: buffer[i++] = input[j] & 1; ...