1 |
h08 |
CS56 M16 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 9am or 10:30am |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h08: Observer Design Pattern (HFDP 2)
ready? | assigned | due | points |
---|---|---|---|
true | Fri 07/08 09:00AM | Wed 07/13 09:00AM |
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.)
Reading Assignment: HFDP is “Head First Design Patterns”, the second required textbook for the course. Please Read HFDP Chapter 2 along with the online reading notes. Then, answer the questions below.
- (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 (either 9am or 10:30am) in the space indicated. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
-
(20 pts) Chapter 2 mentions that Java Swing implements the Observer pattern. Briefly describe how the Observer pattern is used in Java Swing.
-
(10 pts) When implementing the observer pattern, there are observers, and subjects. If you are writing your own code that implements the pattern, which of these is more likely to be true?
Explain your answer.
- Each subject maintains a list of observers
- Each observer maintains a list of subjects
-
The observer pattern is one way of implementing the principle of "loose coupling".
-
(10 pts) What is the principle of “loose coupling”?
-
(10 pts) What is the benefit of using “loose coupling” when writing software?
-
(10 pts) How, specifically, does the observer pattern help to provide these benefits?
-
-
The `java.util` package contains an `Observable` interface and an `Observer` class.
HFDP Chapter 2 describes two implementations of a Weather display device. In each case, there is an object that is responsible for encapsulating the current conditions: temperature, humidity, and pressure.
* The first of these two implementations implements its own version of the observer pattern from scratch
* The second one uses `java.util.Observable` and `java.util.Observer`.
-
(10 pts) One of these uses the pull model, and the other one uses the push model. Are these words “push” and “pull” written from the observer’s point of view, or the subject’s point of view?
-
(5 pts) Describe one advantage of the pull model.
-
(5 pts) Describe one advantage of the push model.
-
(10 pts) In the java.util. version of the code, there is a
setChanged()
method. What is the purpose of that method in the code?
-