Jump to content
Book Questions (page 71)
2 replies to this topic
Posted 24 July 2014 - 09:25 AM
I have some questions about what I read on page 71 of the Head First Design Patterns book. The page discusses the java.util.Observable's design.
1) What does this mean: "First, because Observable is a class, you have to subclass it. That means you can't add on the Observable behavior to an existing class that already extends another superclass." (3rd paragraph)
So what i understand is that it is saying that because Java and in my case C# doesn't allow for multiple inheritance, I can't inherit and extend the behavior from the Observable class if my object is also inheriting from another class. (To me this statement could have been unpacked more. Typing this has helped me understand it better. I hope.)
2) I'm not sure I understand the following sentences either: "If you look at the Observable API, the setChanged() method is protected. So what? Well, this means you can't call setChanged() unless you've subclassed Observable. This means you can't even create an instance of the Observable class and compose it with your own objects, you have to subclass." (5th paragraph)
I guess the key here is that I have to "look at the Observable API" somewhere online to understand what it is saying here.
Posted 24 July 2014 - 07:22 PM
Yes, you understood it perfectly.
Not only that, but you have to have an understanding of what "protected" means, which can mean different things in different languages. (We do assume some basic OO knowledge in the book, but I agree, this is a bit of a stretch).
Anyway, for this one in particular, it means I can't write:
Observable wo = new Observable(); wo.setChanged();
I must subclass in order to be able to call setChanged. So it's just a bit limiting in terms of how you use Observable.
Posted 31 July 2014 - 09:18 PM
Thanks very much for taking the time to answer my questions! I greatly appreciate it.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users