Decorator - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Decorator

Description:

Decorator: Motivation & Application. Subclassing can only add functionality at runtime ... Decorator: Consequences. Positives. More flexibility than static inheritance ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 10
Provided by: cseW
Category:
Tags: decorator

less

Transcript and Presenter's Notes

Title: Decorator


1
Decorator
  • Intent
  • Add additional responsibilities and functionality
    to objects dynamically
  • Also known as Wrapper
  • Example a Text Window

2
Decorator Motivation Application
  • Subclassing can only add functionality at runtime
  • Avoid enumerating all possible sub classes
  • Such as adding a border function to text window.
  • Use with optional functionality

3
Decorator Structure
  • Participants Component, ConcreteComponent,
    Decorator, ConcreteDecorator

4
Decorator Consequences
  • Positives
  • More flexibility than static inheritance
  • Avoids feature laden classes high in hierarchy
  • Negatives
  • Lots of little objects
  • Interface conformance

5
Flyweight
  • Intent Use sharing to support large numbers of
    fine-grained objects efficiently
  • Origin
  • A boxing class which includes fighters weighing
    less than 112 lb (50 kg) but above 108 lb.
  • Example Character in a word processor

6
Flyweight Motivation Application
  • Applications that could benefit from using
    objects
  • But the objects are very small and numerous

7
Flyweight Structure
  • Participants Flyweight, ConcreteFlyweight,
    UnsharedConcreteFlyweight, FlyweightFactory,
    Client

8
Flyweight Consequences
  • Positives
  • Space saving by using shared objects
  • Adds functionality to the application
  • Negatives
  • Adding processing time of computing extrinsic
    state
  • Time can be reduced

9
Any Questions?
Write a Comment
User Comments (0)
About PowerShow.com