17
PRESENTATION ON DECORATOR PATTERN By RAHUL TAWADE

PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

PRESENTATION ON DECORATOR PATTERN

By RAHUL TAWADE

Page 2: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

CONTENTS

Introduction

Decorator Pattern

Class Diagrams

General Scenario

Examples of Design pattern

Code Demonstration

Where used in Java

Reference

Page 3: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

INTRODUCTION

DESIGN PATTERN

What is Design Pattern?

“In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.”

Simple words: A design pattern is just a way to design the solutionfor a particular problem.

These solutions were obtained by trial and error by software developers over quite a substantial periodof time.

GANG OF FOUR(GOF) ???

Page 4: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

INTRO CONT..

What is Gang of Four (GOF)? In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John

Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software

These authors are collectively known as Gang of Four (GOF).

Types of Design Patterns :

1) Creational Patterns : These design patterns provide a way to create objects while hiding the

creation logic

2) Structural Patterns : These design patterns concern class and object composition

3) Behavioural Patterns : These design patterns are specifically concerned with communication

between objects.

4) J2EE Patterns : These patterns are identified by Sun Java Center.

Page 5: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

DECORATOR PATTERN

Structural Pattern

The Decorator Pattern attaches additional responsibilities to an object dynamically.

This pattern creates a decorator class which wraps the original class and provides additional functionality

Steps :1. Create an interface.2. Create concrete classes implementing the same interface.3. Create abstract Decorator class implementing the interface.4. Create concrete decorator class extending the abstract Decorator class.5. Use the concrete Decorator to decorate objects.

Page 6: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Class diagram

Page 7: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

General Scenarios

Page 8: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

General Scenarios Cont…

Page 9: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Coffee Shop Scenario

Page 10: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Coffee Shop using Decorator:

Fig: Class Diagram

Page 11: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Code

Interface :

Page 12: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Code

Concrete Class :

Page 13: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Code

Abstract Decorator class

Page 14: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Code

Concrete Decorator

Page 15: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Code

Test class

Page 16: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Output

Page 17: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original

Decorator Pattern Used in Java