only connect (ch2 of gof)msdl.cs.mcgill.ca/people/hv/teaching/softwaredesign/lectures/lectur… ·...

23

Upload: others

Post on 27-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:
Page 2: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Only connect ... (Ch2 of GoF)# Composite: represent document structure,

# Strategy: different formatting algorithms

# Decorator:embellishing the user interface

# Abstract Factory: multiple look-and-feel standards

# Bridge:multiple windowing platforms

# Command: undo-able user operations

# Iterator:traversing object structures

# Visitor: add functionality independent of document's structure

Page 3: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Composite Pattern

Page 4: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Composite Pattern: Glyphs

Page 5: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Strategy Pattern (aka Policy)Define a family of algorithms, encapsulate each one, and make them interchangeable.

Strategy lets the algorithm vary independently from clients that use it.

Example: line breaking

Page 6: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Strategy Pattern

Page 7: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Embellishing: Decorator Pattern

Page 8: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Decorator Pattern

transparent enclosure

● single-child composition (instead of inheritance) ● compatible interfaces (unlike adapter)

Page 9: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Decorator Pattern

Page 10: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Related to ... Facade Pattern

Abstraction to minimize communication/dependency

Page 11: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Facade Pattern example

Page 12: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Abstract Factory Pattern

Create families of related products

Page 13: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Abstract Factory: products

Page 14: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Abstract Factoryis usually a Singleton

Page 15: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Bridge Pattern

Intent: Decouple an abstraction from its implementation so that the two can vary independently (and dynamically).

Aka: Handle/Body

Supporting multiple UI platforms

Page 16: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Bridge Pattern

Page 17: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Bridge Pattern

Page 18: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Operations: Command Pattern

Page 19: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Command Pattern (invoke)

Page 20: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Command Pattern: undo/redo

Page 21: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Iterator Pattern

Page 22: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Traversal vs. Traversal Actions

Page 23: Only connect (Ch2 of GoF)msdl.cs.mcgill.ca/people/hv/teaching/SoftwareDesign/lectures/lectur… · Abstract Factory Pattern Create families of related products. Abstract Factory:

Visitor Pattern