Tuesday, June 26, 2007

A Singleton thought

Here I am depicting a small and very simple pattern, the most familiar singleton design pattern. when we say singleton it should not create more than one instance at any point of time and there by it should ensure a class has only one instance and provide a global point of access to it.
So, below is an example.

class Singleton
// Static members are lazily initialized.
// .NET guarantees thread safety for static initialization
private static readonly Singleton instance;
// Note: Constructor is 'protected'
protected Singleton()
{ }
public static Singleton Instance()
return instance;

We are giving a protected constructor because the derived classes also should be able to instantiate this, then only they can derive or else if we use a private constructor the derived class will not be able to instantiate their failing in execution. In other words it will indirectly provide or behave as a sealed class, a perfect singleton

Friday, June 22, 2007

An initial design thought

This is a small introduction to Design patterns. Design patterns are solutions to software design problems you find repeatedly in real-world application development or in other words, it is solutions to commonly encountered programming challenges. It describes about design and interaction of objects which are mainly comprised of reusable object-oriented elements. It is a description or template for how to solve a problem that can be used in many different situations Thus it can be considered as parts providing a strong foundation in building good software architecture which will make room even the future changes very easily

Most novice developers think design patterns as an insignificant clutter. But actually speaking it is a very powerful paradigm in the world of software architecture which will bring us proven defect free results. It can really speed up the development process by providing tested, proven development paradigms if you use it in a proper way, I mean in an exact context, domain.

Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns

Design patterns deal specifically with problems at the level of software design. But when I say Design patterns are very powerful paradigm in the world of software architecture, you must not confuse it with architectural patterns.
Architectural patterns are software patterns that offer well-established solutions to architectural problems in software engineering. A pattern describes an optimal solution to a common problem within a specific context of an application. To differentiate, we can take an example of Publisher-Subscriber pattern and MVC (Model-view-controller)

Here Publisher-Subscriber pattern is a design pattern where as MVC is an architectural pattern build based upon on the Publisher-Subscriber pattern. For an instance example of MVC we can say that applications like MS word, visual studio editor. SQL query analyzer will be using this architectural pattern as its base.

Design patterns can be classified mainly into any one of the following.

Fundamental patterns – basic building blocks like composite patterns
Creational patterns – which deal with the creation of objects like Builder, factory etc
Structural patterns – that ease the design by identifying a simple way to realize relationships between entities.
Behavioral patterns – that identify common communication patterns between objects and realize these patterns.