1
h13
CS56 F16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm, 5pm or 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"

h13: The Decorator Pattern (HFDP 3)

ready? assigned due points
true Mon 10/24 12:30PM Mon 10/31 12:30PM

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 three lowest scores (if you have zeros, those are the three lowest scores.)


This homework, and the one that follows, both concern HFDP Chapter 3. Please read that chapter, and then answer the questions on this homework, and the next one.

Please also read this short blog post by Robert C. Martin (Uncle Bob), author of the popular book “Clean Code”, and “Clean Coder”. I’ll ask a question about this article on a future homework assignment, but it will also help to read it before you do this 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 or 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. In Chapter 3, the Open/Closed principle is presented in the context of the Decorator pattern.
    1. (10 pts) Fill in the two blanks to result in the statement of this principle.

      Open for ______________________________________ closed for __________________________________.

    2. (20 pts) Ok, that was the easy part; you just had to find the words in the chapter. Now, the harder part: explain what this means in your own words. "In your own words" means, don't just write down words for the book. Read the book, then put the book down, and write what you've learned as if you were explaining it to someone.
  3. (20 pts) (You may want to skim through HFJ Chapter 14 before answering this question.) The standard Java library classes that implement input and output streams use the Decorator pattern. Describe how the Decorator pattern is used here, and what benefits it provides.
  4. The decorator pattern features both composition and inheritance.
    1. (20 pts) How is composition used in the Decorator pattern?
    2. (20 pts) How is inheritance used in the Decorator pattern? (Note: there is a particular purpose for which inheritance is used in the Decorator pattern. The book describes this very specifically.)

http://UCSB-CS56-F16.github.io/hwk/h13