From "Design Patterns"
🎧 Listen to Summary
Free 10-min PreviewApplying and Selecting Design Patterns
Key Insight
Selecting the appropriate design pattern from a catalog requires a methodical approach. One strategy involves considering how patterns address fundamental design problems, such as effectively finding objects, determining their optimal granularity, or precisely specifying their interfaces and implementations. Another effective method is to scan the 'Intent' sections of patterns, utilizing classification criteria like 'purpose' (creational, structural, behavioral) and 'scope' (class or object) to narrow down the search to patterns most relevant to the problem at hand. Additionally, studying the interrelationships between patterns, often depicted graphically, can guide designers toward a suitable pattern or a group of related patterns.
Further selection strategies include examining patterns based on their common purpose, such as comparing different creational patterns to understand their nuances, or by identifying specific causes of redesign that a pattern is designed to mitigate. A proactive and powerful approach is to analyze which aspects of a design are intended to be variable, as many patterns explicitly encapsulate concepts that are likely to change. This involves consulting resources that list the design aspects patterns allow to vary independently, thus enabling changes without requiring a complete redesign and significantly enhancing system flexibility.
Once a design pattern has been chosen, its effective application follows a systematic multi-step process. Initially, the designer should read through the pattern for a high-level overview, with particular attention to the 'Applicability' and 'Consequences' sections to ensure its suitability. Subsequently, a detailed study of the 'Structure,' 'Participants,' and 'Collaborations' sections is crucial to understand the pattern's components and their interactions. Reviewing the 'Sample Code' provides concrete implementation examples. Practical application involves choosing meaningful, application-specific names for pattern participants and operations, defining classes, interfaces, inheritance relationships, and instance variables, and finally, implementing operations while leveraging hints from the 'Implementation' section and examples.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Design Patterns summary with audio narration, key takeaways, and actionable insights from Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.