presentation on decorator pattern · the decorator pattern attaches additional responsibilities to...

Post on 30-Sep-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PRESENTATION ON DECORATOR PATTERN

By RAHUL TAWADE

CONTENTS

Introduction

Decorator Pattern

Class Diagrams

General Scenario

Examples of Design pattern

Code Demonstration

Where used in Java

Reference

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) ???

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.

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.

Class diagram

General Scenarios

General Scenarios Cont…

Coffee Shop Scenario

Coffee Shop using Decorator:

Fig: Class Diagram

Code

Interface :

Code

Concrete Class :

Code

Abstract Decorator class

Code

Concrete Decorator

Code

Test class

Output

Decorator Pattern Used in Java

top related