Flyweight Design Pattern - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Flyweight Design Pattern

Description:

Different ways to compose objects to realize new ... Exercise 2. Behavioral Patterns. To help define assignment of responsibilities between objects. ... – PowerPoint PPT presentation

Number of Views:180
Avg rating:3.0/5.0
Slides: 14
Provided by: Adw7
Category:

less

Transcript and Presenter's Notes

Title: Flyweight Design Pattern


1
Flyweight Design Pattern
Adwoa Donyina Chaitanya Bhatt
2
Overview
  • Structural Design Patterns
  • FlyWeight
  • Example and Exercise 1 and 2
  • Related Pattern State Pattern
  • Example

3
Structural Patterns
  • Composition of Classes and Objects to form larger
    structures.
  • Structural Class Patterns
  • Use of Inheritance to compose interfaces or
    implementations.
  • Structural Object Patterns
  • Different ways to compose objects to realize new
    functionality.

4
Structural Patterns
  • Class Patterns
  • Adapter
  • Object Patterns
  • Composite
  • Proxy
  • Flyweight
  • Façade
  • Decorator
  • Bridge

5
Flyweight Design Pattern
  • A shared object that can be used in multiple
    contexts.
  • Applicability
  • Lots of Objects
  • Most Objects can be made extrinsic.
  • Have pools of objects with common states
  • Objects Identity is not important

6
Flyweight Design Pattern
7
Flyweight Design Pattern
  • Intrinsic V.S. Extrinsic
  • Intrinsic is stored in the flyweight it stores
    information that is independent of the context so
    its sharable.
  • Extrinsic Depends on and varies with the
    context. Client passes in the extrinsic state.

8
Flyweight Design Pattern
  • Concrete Flyweight
  • Sharable
  • Stored states are intrinsic
  • Unshared Concrete Flyweight
  • Not Sharable
  • Stored states are context driven

9
Flyweight Design Pattern
  • Consequences
  • Flyweights introduce run-time costs associated
    with transferring, finding, and/or computing
    extrinsic state Costs are offset by space savings
    and depend on
  • Reduction in the total of objects
  • Amount of intrinsic state per object
  • Whether extrinsic state is computed or stored
  • Often State Pattern is implemented as Flyweights

10
Flyweight Design Pattern
  • Example
  • Exercise 1
  • Map the flight path!!! Ok that doesnt make
    sense.
  • Exercise 2

11
Behavioral Patterns
  • To help define assignment of responsibilities
    between objects.
  • Communication between Classes and Objects
  • Eg. State design pattern

12
State Design Pattern
  • Allow an object to alter its behavior when its
    internal state changes.
  • The object will appear to change its class.

13
Flyweight Design Pattern
Example 2
Write a Comment
User Comments (0)
About PowerShow.com