decorator design pattern

Post on 13-Jan-2017

206 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Decorator Design Pattern

CSC305GC RAPID APPLICATION DEVELOPMENTGROUP 13

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.

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

4

Decorator

Proxy

Composite

Flyweight

Adapter

Façade

Bridge

Structural

5

Decorator 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

7

UML class diagram

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)

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

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.

11

Demo

12

13

14

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

top related