CSC 313 – Advanced Programming Topics. Decorator Pattern Intent.

Slides:



Advertisements
Similar presentations
Computer Science 313 – Advanced Programming Topics.
Advertisements

Chapter 3: The Decorator Pattern
CSC 313 – Advanced Programming Topics. Today’s Goal  Make you forget reading that was assigned  I went back & reviewed others; none like this one 
Computer Science 313 – Advanced Programming Topics.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Feedback: Keep, Quit, Start
Previous finals up on the web page use them as practice problems look at them early.
CSE 130 : Winter 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 7: Polymorphism.
Exam Questions Chain of Responsibility & Singleton Patterns Game Design Experience Professor Jim Whitehead February 4, 2009 Creative Commons Attribution.
Donald Knuth [F]orget about small efficiencies, say about 97% of the time.
RECURSIVE PATTERNS WRITE A START VALUE… THEN WRITE THE PATTERN USING THE WORDS NOW AND NEXT: NEXT = NOW _________.
Computer Science 313 – Advanced Programming Topics.
BACS 287 Basics of Object-Oriented Programming 1.
CSC 313 – Advanced Programming Topics. Why Recurse?  Recursion is useful, powerful technique  Often yields compact, easy-to-read code  Highlights all.
Prof. Matthew Hertz WTC 207D /
CSC 313 – Advanced Programming Topics. Lindsay Lohan Economy  Studies investigated economy of celebrities  Direct earnings from movies, music, TV, ads.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
CSC 313 – Advanced Programming Topics. Observer Pattern Intent  Efficiently perform 1-to-many communication  Easy to respond dynamically when event(s)
Computer Science 313 – Advanced Programming Topics.
Prof. Hertz (as told by xkcd.com)‏. Computer Science 313 – Advanced Programming Topics.
Albert Einstein Two things are infinite: the universe & human stupidity; and I'm not sure about the universe.
Beware of bugs in the above code; I have only proved it correct, not tried it.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Jan Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern.
Computer Science 313 – Advanced Programming Topics.
Decorator Pattern So many options!. Starbuzz Coffee  Want to offer a variety of combinations of coffee and condiments  Cost of a cup depends on the.
CSC 170 Computing: Science and Creativity
Computer Science 313 – Advanced Programming Topics.
CSC 313 – Advanced Programming Topics. Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?
Computer Science 313 – Advanced Programming Topics.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
CSC 313 – Advanced Programming Topics. Observer Pattern in Java  Java ♥ Observer Pattern & uses everywhere  Find pattern in JButton & ActionListener.
Computer Science 313 – Advanced Programming Topics.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
Computer Science 313 – Advanced Programming Topics.
CSC 313 – Advanced Programming Topics. Strategy Pattern Usage public class RubberDuck extends Duck { FlightBehavior flyBehavior; QuackBehavior quackBehavior;
Unit 3: Socialization What is it? It’s all about PEOPLE.
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
CSC Programming for Science Lecture 10: Boolean Expressions & More If ­ Else Statements.
CSE 373: Data Structures and Algorithms
I Like Ike I have always found that plans are useless, but planning is indispensable.
Fred Brooks Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Huang-Ming Huang, Shih-Ling Chen, Sajeeva Pallemulle.
1 Programming for Engineers in Python Autumn Lecture 8: Recursion.
Computer Science 313 – Advanced Programming Topics.
Why isn’t (1, 1) a solution of the system of linear inequalities y > -x and y > x +1?
Object-Orientated Analysis, Design and Programming
Types for Programs and Proofs
Chapter 5:Design Patterns
Computers as an Expressive Medium
Introduction to Design Patterns
Week 4 Object-Oriented Programming (1): Inheritance
MSIS 670 Object-Oriented Software Engineering
Object Oriented Design Patterns - Creational Patterns
Object Oriented Design Patterns - Structural Patterns
OO Design Patterns - Decorator
Decorator Pattern Richard Gesick.
Object Oriented Design Patterns - Behavioral Patterns
Dr. Joe Anderson September 6, 2017
Refactoring Types Blake Duncan.
CSE 373 Data Structures and Algorithms
Design Patterns Lecture part 1.
CSE 373: Data Structures and Algorithms
Presentation transcript:

CSC 313 – Advanced Programming Topics

Decorator Pattern Intent

Pizza Decorator Pattern Visual

Decorator Pattern Creation Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe = new Whip(joe); joe = new Tall(joe); int mortgage = joe.cost();

Decorators’ Dirty Secrets  Decorators are subclasses of main class

Decorators’ Dirty Secrets  Decorators are subclasses of main class

Decorators’ Dirty Secrets  Decorators are subclasses of main class  Almost recursive

Meet the Decorator Classes

Decorator Pattern Usage Drink martini = new Gin(); martini = new Vermouth(martini); martini = new Ice(martini); martini = martini.shake();

Decorator Pattern Usage Drink martini = new Gin(); martini = new Vermouth(martini); martini = new Ice(martini); martini = martini.shake(); = martini.pour();

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe bev

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe bev

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe = new Whip(joe); joe bev

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe = new Whip(joe); joe = new Mocha(joe); joe bev

Decorator Pattern Usage Beverage joe = new HouseBlend(); joe = new Mocha(joe); joe = new Whip(joe); joe = new Mocha(joe); int mortgage = joe.cost(); joe bev

Decorator Example

Decorators: Good or Bad Pros:  Invisibly add to classes  Enable code reuse  Limit code written  Creates classes that are closed to modification Cons:  No reality in hierarchy  Use mangled recursion  Slow, polymorphic calls used everywhere

For Next Lecture  Lab #3 available on Angel  Asks you to implement Decorator Pattern but  Have time Friday, but may want help profiling  Two (short) readings available on web  Is this method hot or uglier than ____ Mom?  What rules of thumb exist for where to optimize?  How to express improvement so it is meaningful?  Could we compute maximum benefit from opts?