Wednesday, January 20, 2010

Understanding Design Patterns

What is Design Pattern and why it is so important?

Before explaining what design pattern is, we will look into why we need to learn design patterns. As a software or application developer, we do write a lot of code every day to deliver the software/application. Most of the people write the code in different ways; someone writes all logic into one single file and someone separates that code into multiple files.

In either case we can deliver a working software/application but the thing is how flexible your codes to make any changes or add/removes one of the features. According to my experience, it is very difficult to make any changes to such code or we need to write the same code again and again with few modifications.

That’s why design patterns came to rescue. Until now I haven’t told you what design pattern is, don’t curse me for that. That’s what I explaining next.

What is Design Pattern?

Design pattern is a reusable solution to a common problem. It is just a template for how to solve a problem that can be used in different situations.

Benefits of Design Pattern


  • Provide a way to solve issues related to software/application development using proven solution.
  • Facilitates the development of highly cohesive (organized) modules with minimal coupling.
  • Isolate the variability (inconsistent) that may exist in the system requirements, so that making the overall system easier to understand and maintain.
Design patterns were originally grouped into 3 different categories
  1. Creational
  2. Structural
  3. Behavioral

There are few more, i.e., Concurrency and Architectural
Creational Patterns:
Creational patterns deals with object creation mechanisms. If we are unable to manage the object creation properly, it could result in design problems or added complexity to the design.
Creational design patterns solve this problem by somehow controlling the object creation.
Structural Patterns:
Structural patterns ease the design by identifying a simple way to realize relationships (inheritance) and entities (objects).
Behavioral Patterns:
Behavioral patterns are most specifically concerned with communication between objects.
Concurrency Pattern:
Concurrency patterns mainly deal with multi threaded paradigm.
Architectural Design pattern:
Architectural design patterns describe solutions to architectural problems and work efficiently. It expresses a fundamental organization structure schema for a software system, which consists of subsystems, their responsibilities and interrelations. In comparison to design patterns, architectural patterns are larger in scale.

Mos important point to note is that design patterns are not stubborn. So one design patterns may use some other design pattern to solve a particular problem.

Also, there is no strict rule when following a design pattern, which means you don't need to copy it word-for-word, or code-by-code. A design pattern is just an approach that has worked well in similar cases for other developers. Not all situations or programming problems are the same. Hence, if we are following a particular design pattern we might need to modify it to suit our custom needs, instead of blindly following it verbatim.

0 comments:

Post a Comment