Design Pattern is a proven approach (well tested solution) or a guideline to structure your code.
Design Pattern is not an algorithm, but it is a best practice (suggestion) for a common type of a problem.
There are total 23 design patterns originally described in a book "Design Patterns: Elements of Reusable Object-Oriented Software" by Erich Gamma and others (commonly referred as "Gang of Four").
Design Patterns are mainly divided into 3 categories:
1. Creational Patterns: approaches that deal with the creation of objects. It emphasizes on the flexibility of object creation.
2. Structural Patterns: These patterns suggest the best ways for creating classes and their relationship with each other.
3. Behavioral Patterns: These patterns provide guidelines for implementing the communication strategy between various objects.
Need for Design Patterns?
Primarily to deal with the change. Changes are common in software life-cycle.
e.g. You need to add new feature, changes to client specifications, you found a critical bug etc ...
And this requires restructuring of the code. It is very hard to anticipate all the problems/changes that could occur in the software ahead of the time. Fortunately, others (smart folks) have been through a lot of experience in software development and they have bundled all that knowledge into "Design Patterns". You can use those guidelines to design your software to avoid most common problems. Design Patterns minimize the impact of the change in your code and helps us to design robust object system which is flexible (open to modifications in the future).
Design patterns provide a shared vocabulary among the fellow developers, efficient ways of communicating the design.
Ultimately design patterns enable you to reuse the years of software development experience. Design patterns save you time, trial and errors.
Formal definition of a Design Pattern is as follows:
"A Design Pattern is a solution to a problem in a context."
Context: The situation in which a pattern applies.
Problem: The goal you are trying to achieve.
Solution: A design that resolves the problem.
No comments:
Post a Comment