1
h06
CS56 S19
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm,5pm,6pm
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h06: HFDP 3: Intro to Design Patterns, Decorator

ready? assigned due points
true Mon 05/20 05:00PM Tue 05/28 05:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the two lowest scores (if you have zeros, those are the two lowest scores.)


NOTE: Due to the Memorial Day holiday on Monday 5/27, this homework will be due on Tuesday 5/28 @ 5pm. You will need to scan your homework and upload a legible .pdf file to Gradescope by the deadline. Be sure to ask our staff or come to office hours if you are unsure how to do this.

Reading Assignment:

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (4pm,5pm,6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.) If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
  2. On pg 86, the book provides a definition of the “Open-Closed Principle”.

    1. (10 pts) In your own words, define what does the Open-Closed Principle means.

    2. (10 pts) How does the Open-Closed Principle apply to the Decorator Design Pattern?

    3. (10 pts) How does the Open-Closed Principle apply to the Strategy Pattern from HFDP Chapter 1?

  3. (10 pts) The figures on pg 89 and 90 wraps Decorators around Components and other Decorators. How are these two classes able to “mirror” each other?

  4. (10 pts) The author asks to draw a picture similar to the figure shown at the top of pg 94 for a “double mocha soy latte with whip.” Draw this picture below.

  5. Pg 100 discusses how the java.io package is based on the decorator pattern.

    1. (10 pts) What functionality does the FileInputStream provide?

    2. (10 pts) What role does the FileInputStream object have in the decorator pattern?

    3. (10 pts) What role do the BufferedInputStream and LineNumberInputStream object have in the decorator pattern?

    4. (10 pts) What additional functionality does the BufferedInputStream add to the FileInputStream? What additional functionality does the LineNumberInputStream add?