GofPatterns GofPatterns

Design Patterns  «Prev  Next»
Lesson 5Why use design patterns?
ObjectiveLearn how design patterns assist programmers.

Design Pattern Benefits and how Design Patterns assist Programmer

Question: Why would you use design patterns?
Answer:The answer is so simple it is almost a tautology: Design patterns are used because they make your job easier.
Design patterns let you write better code more quickly.
However, patterns are not a panacea. Of the five phases of software development, design patterns do almost nothing in the analysis, testing, or documentation phases. Design patterns, as the name implies, have their biggest impact in the design phase of a project.

To be more precise:
  1. Design patterns help you analyze the more abstract areas of a program by providing concrete, well-tested solutions.
  2. Design patterns help you write code faster by providing a clearer picture of how you are implementing the design.
  3. Design patterns encourage code reuse and accommodate change by supplying well-tested mechanisms for delegation[1] and composition[2], and other non-inheritance based reuse techniques.
  4. Design patterns encourage more legible and maintainable code by following well-understood paths.
  5. Design patterns increasingly provide a common language and jargon for programmers.

Focus on Substance, Not Style

Most of the good programmers I know have a certain style that points to professional programming habits. When you encounter good OOP programming, you will see a certain way of doing everything from naming variables to commenting code. Variable names are clear, and comments in the code tell the story of the code so that other programmers know how to connect to their own modules. I have often found that putting in too many comments get in the way of clearly seeing the structure of the code. So, with the goal of being able to see and sense objects as complete entities, the code is not fractionalized by long-winded comments.

Design Patterns Purpose - Quiz

The following quiz contains questions with respect to the purpose of design patterns.
Design Patterns Purpose - Quiz

[1]Delegation: This pattern is one where a given object provides an interface to a set of operations. However, the actual work for those operations is performed by one or more other objects.

[2] composition: Creating objects with other objects as members. Composition should be used when a has-a relationship applies.