Software Design & Architecture, Study notes of Software Development Methodologies

Decorator Design Pattern 2. Structure of Decorator Design Pattern 3. Examples of Decorator Design Pattern

Typology: Study notes

2019/2020

Uploaded on 09/24/2020

danish-zamir
danish-zamir 🇵🇰

1 document

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MIRPUR UNIVERSITY OF SCIENCE AND TECHNOLOGY
DEPARTMENT OF SOFTWARE ENGINEERING
Software Design & Architecture 1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Software Design & Architecture and more Study notes Software Development Methodologies in PDF only on Docsity!

MIRPUR UNIVERSITY OF SCIENCE AND TECHNOLOGY

DEPARTMENT OF SOFTWARE ENGINEERING

Software Design & Architecture 1

Software Design & Architecture (Lecture # 25) Decorator Design Pattern Saba Zafar (Lecturer) Date: 8 September, 2020

DECORATOR PATTERN - DESIGN PATTERN

  • Name: Decorator
  • Problem: You want to add behavior or state to individual objects at run-time. Inheritance is not feasible because it is static and applies to an entire class
  • Solution:
    • The decorator pattern enables us to add new or additional behavior to an object during runtime, depending on the situation
    • Decorators have the same super-type as the objects they decorate
    • One or more decorator objects can be used to wrap an object

DECORATOR PATTERN - DESIGN PATTERN

  • This pattern creates a decorator class which wraps the original class and provides additional functionality
  • The decorator adds its own behavior either before and/or after delegating to the object it decorates
  • Objects can be decorated at any time, so we can decorate objects dynamically at runtime with as many decorators as we like.

DECORATOR PATTERN - DESIGN PATTERN

  • But the Decorator pattern suggests giving the client the ability to specify whatever combination of "features" is desired.
  • This flexibility can be achieved with the following design

DECORATOR PATTERN - DESIGN PATTERN Example: Assault gun is a deadly weapon on it's own. But you can apply certain "decorations" to make it more accurate, silent and devastating

Software Design & Architecture 10 DECORATOR PATTERN - EXAMPLE EXAMPLE: Pizza Topping

THANKS

Software Design & Architecture 11