Showing posts with label C# design patterns. Show all posts
Showing posts with label C# design patterns. Show all posts

Wednesday, March 31, 2010

Comparison of Creational Patterns

According to my experience, you may use each pattern as follow:

1- The Builder pattern is concerned with building a single complex object
(by including the concept of a director that depending on different factories).

2-
The Abstract Factory pattern is concerned with building families of related products (where there are many product hierarchies and a factory for each family of products).

3-
The Factory Method pattern is concerned with instantiating a subclass
of one class hierarchy (where there is a specific reason why one subclass would be chosen over another).

Monday, March 22, 2010

C# implementation of Abstract Factory pattern

The Abstract Factory pattern takes Factory Method Pattern step further, creating families of related products.
The abstract factory can be refined to concrete factories,
each of which can create different products of different types.

The pattern isolates the product definitions and their class names from the
client so that the only way to get one of them is through a factory. For this reason,
product families can easily be interchanged or updated without upsetting the structure
of the client.
An interesting aspect of the Abstract Factory pattern is that the whole product family
can be changed while the application is running.


Wednesday, March 3, 2010

C# Implementation of Factory Method Pattern

Factory Methods encapsulates the creation of related objects
(the Productes) by letting a class (the Creator) deciding which class to instantiate depending on a specific reason.
For example, in case that the creation process depends on user input .

In the world of GIS, there is a map which includes many various layers.
The client chooses what kind of Layers to be added to a given map .


Tuesday, February 23, 2010

C# Implementation of Singleton Pattern

In .NET, more than one thread can execute our Singleton concurrently
because .net is multithreaded.

If our class includes multiple static members, the first reference to
any of those members will trigger the type initializer. Also, class
instatiation will trigger them.

This implementation uses an inner class to make the .NET instantiation fully lazy.

The compiler guarantees the thread safety.