14
Decorator Design Pattern CSC305GC RAPID APPLICATION DEVELOPMENT GROUP 13

Decorator design pattern

Embed Size (px)

Citation preview

Page 1: Decorator design pattern

Decorator Design Pattern

CSC305GC RAPID APPLICATION DEVELOPMENTGROUP 13

Page 2: Decorator design pattern

2

What is the software design pattern?

• IntroductionIn 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.

Page 3: Decorator design pattern

3

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

Page 4: Decorator design pattern

4

Decorator

Proxy

Composite

Flyweight

Adapter

Façade

Bridge

Structural

Page 5: Decorator design pattern

5

Decorator pattern

Page 6: Decorator design pattern

6

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

Page 7: Decorator design pattern

7

UML class diagram

Page 8: Decorator design pattern

8

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)

Page 9: Decorator design pattern

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

Page 10: Decorator design pattern

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.

Page 11: Decorator design pattern

11

Demo

Page 12: Decorator design pattern

12

Page 13: Decorator design pattern

13

Page 14: Decorator design pattern

14

Thank You K. L. Pushpika prasadK. A. H. M. KarunathilakeW. A. M. D. M. BandaraP. P. U. A. Peries