26 October 2008

Design Pattern - Introduction

If you are a software developer, your responsibilities include design, implementation and unit testing the software. Once the software released, the whole bunch of new issues suddenly creeps into your code and then on you will be running after each bug and trying to chase it down to death. In most of the cases, the bug wins and the developers lose. Sometimes, I used to think that there is an egoistic clash between bugs and developers both of them willing to fight till the last breadth. Irrespective of the honest effort, the bugs manifest in multiple forms - usability, functionality, performance, scalability and so many jargons. With current time to market pressures, the software community is pro-actively by changing the software development models - Agile, Iterative, Test Driven Development. These software development models give a framework to tackle the changes in requirements. These days it has become unwritten law to change the requirements, quite often. Even though, we have software development models that offer flexibility, doing the fundamental right will give you a lot more flexibility. Design Pattern is one such tool that helps by providing conceptual solution to common problems and thus decreasing the software development time. 

Design patterns are solutions to common problems. It is not a software tool, framework or library. Design Patterns are simple and effective ideas for common/repeated problems.  Since it is a concept, it can be reused anywhere in software design. The concept of design pattern must have be adopted by software development community taking an inspiration from architecture of buildings or civil engineering. The fundamental concepts and theories of building various types of buildings such as houses, roads, flyovers, auditoriums, cinema halls, communities and etc are same. For example, there are blueprints available to make various types of buildings based on the land terrain, climatic conditions and so many factors. But given a set of requirements, any experienced architect or civil engineer will be able to give you the plan for the building and when followed with fundamental concepts, the building will be made. So, the developers in software community also thought in similar lines and came out with classical ways of solving design problems. Hence, Design Patterns are solutions of common problem.

Like a blueprint, Design Patterns are template for complex problems. Once again going back to the example, the architect or civil engineer will know how to build buildings and what needs to be done. In similar way, Design Patterns are just ideas/concepts. They are not specific to a platform, programming language or an operating system. Design Patterns might have been used atleast millions of times by software developers and the concepts, principles are time tested. Hence most of the Design Patterns states which problem that it is trying to solve and of course the solution. In order to make things clear, apart from the intent and associated text, the design patterns are explained with the help of UML class diagrams.

Design Pattern makes our life easier. Say for example, someone comes to you and asks for "Can you tell the place where people go from one city to another, purchasing tickets. They will also wait on a platform for the vehicle containing a series of boogies pulled by an engine powered by electricity or diesel?" Won't you run from him?. The job would be much easier the person asks for the way to railway station. In software development, without design patterns, the developers need to beat around the bush to express what is there in their mind and Design Patterns makes communication fast, crisp and clear. So, Design Patterns are communication tool.

Having discussed about the design patterns, the rest of the article discusses various types of design patterns. Based on the applicability, the design patterns can be categorized into three main types. They are

1. Creational Patterns which primarily deal with how the objects are created and how to create objects based on a specific situation. The examples of creational patterns are Singleton, Factory, Prototype.

2. Behavioral Patterns identifies common communication patterns between objects and offers flexibility in performing the communication. The examples are State, Strategy, Observer, Chain of Responsibility.

3. Structural Patterns deals with realization of relationships among objects. Decorator, Adapter and Flyweight patterns are examples of structural patterns.

In this blog, we saw the basics of design pattern and its types. In upcoming blogs we shall see about specific design pattern with real world examples, class diagrams and how to apply these concepts into software development.

1. Design Patterns are solution to common and repeated problems
2. Design Patterns are not library, API or framework or source code
3. Design Patterns help developers to communicate fast and to the point.
4. Creational, Structural and Behavioral are three types of Design Patterns

No comments: