Patterns 2020/4/12 Structural Design Patterns Creational - - PowerPoint PPT Presentation

patterns
SMART_READER_LITE
LIVE PREVIEW

Patterns 2020/4/12 Structural Design Patterns Creational - - PowerPoint PPT Presentation

Poly- mor- phism Abstra ction Class OOP Inheri -tance En- capsu- lation Structural Design Kuan-Ting Lai Patterns 2020/4/12 Structural Design Patterns Creational Structural Behavioral Design Patterns Design Patterns Design


slide-1
SLIDE 1

Structural Design Patterns

Kuan-Ting Lai 2020/4/12

OOP

Class Abstra ction Inheri

  • tance

En- capsu- lation Poly- mor- phism

slide-2
SLIDE 2

Structural Design Patterns

Creational Design Patterns

Initialize objects

  • r create new

classes

Structural Design Patterns

Compose

  • bjects to get

new functions

Behavioral Design Patterns

Communication between objects

slide-3
SLIDE 3

Structural Design Patterns

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Façade
  • Flyweight
  • Proxy
slide-4
SLIDE 4
slide-5
SLIDE 5

Adapter Pattern

slide-6
SLIDE 6

Adapter

  • Adapter works as a bridge between

two incompatible interfaces

  • Object adaptor
  • Class adaptor
slide-7
SLIDE 7

Inheritance vs. Composition

slide-8
SLIDE 8

Object Adaptor

  • Client Interface describes a protocol that other classes must follow
  • Adapter is a class that implements the client interface and composite

a service object

slide-9
SLIDE 9

Class Adaptor

  • Inherit from both client and service class
slide-10
SLIDE 10

Example: MediaPlayer

https://www.tutorialspoint.com/design_pattern/adapter_pattern.htm

slide-11
SLIDE 11

Bridge Pattern

  • Split a large class into two separate hierarchies: abstraction and

implementation

slide-12
SLIDE 12

Bridge Example: Colorful Shapes

slide-13
SLIDE 13

Separating Shape and Color

  • The Bridge pattern attempts to solve this problem by switching from

inheritance to composition

slide-14
SLIDE 14

Using Composition to Implement New Function

slide-15
SLIDE 15

Composite Pattern

  • Compose objects into

a tree structure

slide-16
SLIDE 16

Document Structure

  • Recursive composition of text and graphics
slide-17
SLIDE 17

Composite Pattern

slide-18
SLIDE 18

Composite Structure

  • Component

interface describes

  • perations that are common to

both simple and complex elements

  • f the tree
  • Leaf is a basic element without

sub-elements

  • Container (aka composite) is an

element that has sub-elements

slide-19
SLIDE 19

Decorator

  • Attach new behaviors to objects by placing these objects
slide-20
SLIDE 20

Embellishing the User Interface (Decorator)

  • Decorator Pattern: support embellishment by

transparent enclosure

slide-21
SLIDE 21

FACADE

slide-22
SLIDE 22

FACADE

  • Define a new interface for existing many objects
slide-23
SLIDE 23

FLYWEIGHT

  • Fit more objects into RAM by sharing common

parts of state between multiple objects

slide-24
SLIDE 24

Example: Game Displaying

slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27

Proxy

slide-28
SLIDE 28

Proxy Structure

  • Lazy initialization
  • Access control
  • Local execution of a remote

service

  • Logging requests
  • Caching results
  • Garbage collection
slide-29
SLIDE 29

Example: Internet Proxy

https://www.javatpoint.com/proxy-pattern

slide-30
SLIDE 30

References

  • Alexander Shvets, “Dive into Design Patterns,” 2018
  • https://www.tutorialspoint.com/design_pattern/index.htm
  • https://www.javatpoint.com/design-patterns-in-java
  • https://www.startertutorials.com/patterns/select-design-

pattern.html