Sunday, May 20, 2007

Design Patterns

Why Design Patterns ?

  • Knowing concepts like abstraction,inheritance,and polymorphism do not make you a good object oriented designer. Need to think how to create flexible designs that are maintainable and that can cope with changes.
  • Need to build software so that we need to change it ,we could do so with the least possible impact on the existing code.
  • One should spend less time reworking code and try to work more on developing the Program to do lots of magic.

What ?

  • Design patterns represent a wealth of collective knowledge and experience.
  • Design Pattern ensures that common problems are addressed via well-known and accepted Solutions.
  • The proper use of these patterns will help to ensure that systems are malleable, enabling rapid change.

Dump Questions on Design Patterns

  • If design patterns are so great ,why can’t someone build a library of them so I don’t have to ?

Design Patterns are higher level than libraries.They tell us how to structure classes and objects to solve certain problems and it is our job to adapt these design to fit our particular application.

  • Aren’t libraries and frameworks also design patterns ?

Frameworks and libraries are not design patterns; they provide specific implementations that we link into or code.
However ,sometimes libraries and frameworks make use of design patterns in their implementations.


Types of Design Patterns

  • Creational Patterns
    – Involve Object instantiation and all provide a way to decouple a client from the objects it needs to instantiate.
    Patterns : Singleton, Factory Method, Abstract Factory,Builder,Prototype.
  • Structural Patterns
    –Lets you Compose classes or objects into larger structures.
    Patterns : Decorator,Composite,Adapter,Bridge,Façade,Proxy,Flyweight
  • Behavioral Patterns
    –Concerned with how classes and objects interact and distribute responsibility.
    Patterns: Strategy,Observer,Command,Iterator,Template Method.

Design Principles

Listed below the basic design principles as the outcome of design patterns:

  • Encapsulate what varies .
  • Favor Composition over Inheritance .
  • Program to an interfaces ,not implementations.
  • Strive for loosely coupled design between objects that interact.
  • Classes should be open for extension and closed for modification.
  • Depend on abstractions. Do not depend on concrete classes.
  • Principle of Least Knowledge.