Design Patterns Flashcards
What is a design pattern
Description of a problem that reoccurs and an outline of an approach to solving a problem.
What is a framework
partially completed design that can be extended to solve a problem in a domain.
What is an idiom
A small language specific pattern or technique.
Use of Init in constructors
- If many constructors, make each one call a private function init()
- Initialize in one place despite multiple constructors
Essential Elements of Design Patterns
Vocabulary of patterns, need to know where to apply patterns, how to represent components and conditions to be met before using. Use Design Elements
Design Elements:
Relations, Responsibilities, Collaborations.
Patterns are;
name and description of proven solution to problem. Documentation of design decision.
Patterns are not;
Reusable code/libraries. Don’t need complex integrations.
Pattern Format
- Name and Classification
- Intent
- AKA
- Motivation (Sample Problem)
- Applicability (Situation)
- Structure
- Participants
- Collaborators
- Consequences
- Implementation
- Sample Code
- Known Uses
- Related Patterns
Static Factory Methods
- Singleton Pattern will use static factory method
- Advantages over public constructors
- Wrapper Classes used
Factory
Something that creates an instance
State Design Pattern
Connection can be in various state requests, handles differently depending on state. Connection delegates request to state object which changes dynamically.