2/23-2/25 - Design Pattern Flashcards

1
Q

Alexander’s Pattern Language

A
  • Each pattern describes a problem which occurs over and over again and then describes the core of the solution to that problem in way that you can reuse that solution multiple times.
  • A pattern language is an organized way of tackling an architectural problem using patterns
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Software Design Patterns

A
  • Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context
  • They are not full designs or individual classes or libraries
  • Design patterns name common successful ways of building software
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Elements of a Design Pattern

A
  1. Pattern Name
  2. Problem Solved
  3. Solution
  4. Consequences
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Example: A Text Editor

A
Problem: Document Structure
• Primitive glyphs
• Lines
• Columns
• Pages
• Documents
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Composites

A
  • This is the composite pattern
  • Applies to hierarchical structure
  • Leaves and internal nodes have same functionality
  • Composite implements the same interface as the contained elements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Pros of Composites

A
  • Easy to add, remove new object types

* Clean interface, elegant code. No need to iterate over all object types to draw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Cons of Composites

A
  • Have to fight to add corner cases

* Hard to enforce that a composite only has certain elements (Ex. A line does not contain columns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Problem: Enhancing the User Interface

A
  • We want to add borders, scrollbars, both
  • How do we incorporate this into the physical structure?
  • Object behavior can be extended using inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Using Inheritance to Extend Object Behavior

A
  • Major drawback: inheritance structure is static
  • Subclass elements of Glyph: BorderedGlyph, ScrollGlyph, etc.
  • Leads to a lot of classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Decorators

A
  • This is the decorator pattern
  • A way of adding responsibilities to an object
  • Problem: Supporting look and feel settings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Using Decorators to Add Responsibilities to an Object

A
  • Decorations can be chosen dynamically

* Transparent enclosure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Problem: Supporting look and feel settings

A

• Different look and feel standards

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Factories

A
  • This is the factory pattern
  • A class which abstracts the creation of objects. Different instances provide alternative implementations if that family
  • “current” factory is still a global variable. Can be changed even at runtime
  • Problem: Supporting multiple window systems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Problem: Supporting multiple window systems

A
  • Big interfaces
  • Different models of window operations
  • Different functionality
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Bridge Pattern

A

• This is the bridge pattern

• We have two hierarchies
• Logical – the view of our application, tuned to our needs
• Implementation – interface to the outside world; abstract base class with multiple
Implementations

  • Logical implementation views can evolve independently as long as the bridge is maintained
  • Problem: Spell checking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Logical Hierarchy (Bridge Pattern)

A

the view of our application, tuned to our needs

17
Q

Implementation Hierarchy (Bridge Pattern)

A
  • Interface to the outside world

* Abstract base class with multiple implementations

18
Q

Problem: Spell checking (Bridge Pattern)

A

Solution: iterators

  • Hide the structure of a container from clients
  • Iterators work well if we don’t need to know the type of elements being iterated over
19
Q

Visitor Pattern

A
  • The visitor pattern is more general
  • Iterators provide traversal of containers
  • Visitors allow traversal and type-specific actions on container elements
  • Separate traversal from action. Have a do-it method for each element type
  • Extremely powerful pattern. Is non-obvious
  • Whenever you have a hierarchical structure of heterogeneous elements write support for visitors. Other traversals can be written as a subclass of visitors
20
Q

Strategy Pattern

A
  • Strategy pattern isolates variations in algorithms
  • Formatter is the strategy. Compositor is the context
  • General principle: encapsulate variation
    • i.e. Define abstract classes for things that are likely to change
21
Q

Command Pattern

A

User essentially has a small programming language that is finite

  • Abstraction makes this explicit
  • Class structure can represent all possibilities explicitly