1 |
h09 |
CS56 M18 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 9:30am or 11am |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h09: The Decorator Pattern (HFDP 3)
ready? | assigned | due | points |
---|---|---|---|
true | Fri 08/31 12:20PM | Thu 09/06 09:30AM |
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.)
PDF of H09 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”. The question about this appears on H10 but if you read it now, it may help your understanding of the Open/Closed principle.
- (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 (9:30am or 11am) 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.
-
In Chapter 3, the Open/Closed principle is presented in the context of
the Decorator pattern.
- (10 pts) Fill in the two blanks to result in the
statement of this principle.
Open for ______________________________________ closed for __________________________________.
- (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.
- (10 pts) Fill in the two blanks to result in the
statement of this principle.
- (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.
- The decorator pattern features both
composition and inheritance.
- (20 pts) How is composition used in the Decorator pattern?
- (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.)