What is design a pattern?

A design pattern is the abstract structure of a common solution to a common problem in object-oriented programming. It abstracts something to do from existing data structures, algorithms, code , classes and objects that does it. So the common purpose of design patterns is to make objects and classes reusable and extensible.

Design patterns are a means to communicate, identify, and remember solutions to common problems. It names, explains and evaluates a solution to a common probelm. Each pattern has four essential elements, the pattern's name, the problem it solves, the solution to the problem and the consequences of that solution.

There are three types of design patterns (1) Creational patterns (2) Structural patterns and (3) Behavioral patterns. Creational patterns are used to create objects of the right class of a problem. It is helpful when using polymorphism and there is a need to choose between different classes at runtime rather than at compile time. Structural patterns form larger structures from individual classes. Behavioral patterns describe interactions between objects.

Patterns also can be divided based on their scope. Object patterns deal with the relationship between objects. It allows instances of different classes to be used in the same place in a pattern, avoids fixing the class that accomplished a given task at compile time rather than at runtime, and uses object composition to establish relationships between objects. Class patterns deal with the relationship between classes and their subclasses. It uses inheritance to establish relationships and generally fixes the relationships at compile time. So it is less flexible and dynamic than object patterns.

The design patterns themselves follow a pattern. Each pattern has

  • Intent which states the problem that the pattern addresses.

  • Motivation which describe the problem.

  • Applicability which describes the circumstances under which the pattern can be used or not used.

  • Structure which gives an object or class diagram.

  • Participants lists the classes and objects along with its responsibilities.

  • Collaboration which describes how classes and objects outside the pattern interact with the pattern.

  • Consequences list positive and negative results of using the pattern.

  • Implementation is the set of code that uses the pattern.

  • Known Uses provides some practical real-world examples which use the pattern.

  • Related Patterns is the list of other design patterns which are closely related.

What is a Design Pattern?
Creational Design Pattern
Structural Design Pattern
Behavioral Design Pattern
Why use Design Patterns?
Want to learn more?

About Us | Contact Us | Disclaimer | Privacy Policy | ©2008 thewebguru.com