1 |
h12 |
CS56 F17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 2pm, 4pm or 5pm |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h12: Observer Design Pattern (HFDP 2)
ready? | assigned | due | points |
---|---|---|---|
true | Tue 10/31 09:30AM | Tue 11/07 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.)
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.
PLEASE DO NOT STAPLE or otherwise connect the pages if you turn in on two sheets of paper. Please just write your name on both and turn in as separate sheets. Stapling, taping, etc. jams the scanner and costs money for repairs!
- (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 (2pm, 4pm or 5pm) 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.
-
(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?
-