Decorator Design Pattern
CSC305GC RAPID APPLICATION DEVELOPMENT
GROUP 13
What is the software design pattern?
• Introduction
In software engineering, a design pattern is a general
reusable solution to a commonly occurring problem within a given
context in software design. A design pattern is not a finished design
that can be transformed directly into source or machine code.
2
Creational
Behavioral Structural
Deal with object
creation
mechanism
Deal with common
communication
between objects
Ease the design
by identifying a
simple way to
realize
relationships
between entities.
• Classification
3
Decorator
Proxy
CompositeFlyweight
Adapter
Façade
Bridge
4
Structural
Decorator
pattern
5
What Is Decorator Pattern?
The decorator pattern is a design pattern that
allows behavior to be added to an individual object,
either statically or dynamically, without affecting the
behavior of other objects from the same class.
Before Decorating After Decorating
6
UML class diagram
7
Uses of decorator pattern
• Graphics world(as illustrated)
• I/O namespace of.net
• System.IO.Stream
• System.IO.BufferedStream
• System.IO.FileStream
• System.IO.MemoryStream
• Cross platform application(Mobile/Desktop)
8
Advantages and Disadvantages
• Advantages
• fewer classes than with static inheritance
• dynamic addition/removal of decorators
• keeps root classes simple
• Disadvantages
• proliferation of run-time instances
• abstract Decorator must provide common interface
• Inheritance solution has an explosion of classes
• If another view were added such as Streamed Video View, double
the number of Borders/Scrollbar classes
9
Related Patterns
• Adapter: A decorator is different from an adapter
in that a decorator only changes an object‘s
responsibilities, not its interface; an adapter will
give an object a completely new interface.
• Strategy : A decorator lets you change the skin of
an object; a strategy lets you change the guts.
10
Demo
11
12
13
Thank You
K. L. Pushpika prasad
K. A. H. M. Karunathilake
W. A. M. D. M. Bandara
P. P. U. A. Peries
14

Decorator design pattern

  • 1.
    Decorator Design Pattern CSC305GCRAPID APPLICATION DEVELOPMENT GROUP 13
  • 2.
    What is thesoftware design pattern? • Introduction In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. 2
  • 3.
    Creational Behavioral Structural Deal withobject creation mechanism Deal with common communication between objects Ease the design by identifying a simple way to realize relationships between entities. • Classification 3
  • 4.
  • 5.
  • 6.
    What Is DecoratorPattern? The decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. Before Decorating After Decorating 6
  • 7.
  • 8.
    Uses of decoratorpattern • Graphics world(as illustrated) • I/O namespace of.net • System.IO.Stream • System.IO.BufferedStream • System.IO.FileStream • System.IO.MemoryStream • Cross platform application(Mobile/Desktop) 8
  • 9.
    Advantages and Disadvantages •Advantages • fewer classes than with static inheritance • dynamic addition/removal of decorators • keeps root classes simple • Disadvantages • proliferation of run-time instances • abstract Decorator must provide common interface • Inheritance solution has an explosion of classes • If another view were added such as Streamed Video View, double the number of Borders/Scrollbar classes 9
  • 10.
    Related Patterns • Adapter:A decorator is different from an adapter in that a decorator only changes an object‘s responsibilities, not its interface; an adapter will give an object a completely new interface. • Strategy : A decorator lets you change the skin of an object; a strategy lets you change the guts. 10
  • 11.
  • 12.
  • 13.
  • 14.
    Thank You K. L.Pushpika prasad K. A. H. M. Karunathilake W. A. M. D. M. Bandara P. P. U. A. Peries 14