O'Reilly Forums: Book Questions (page 71) - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Book Questions (page 71) Questions about statements made in the book I don't understand.

#1 User is offline   JacobPressures 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 24-July 14

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.

Thanks!
0

#2 User is offline   Beth Robson 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Employee
  • Posts: 376
  • Joined: 17-September 08
  • Gender:Female
  • Location:Seattle, WA
  • Interests:I am interested in computer science, the Web, social media and the internet, Mac development, and adult learning.

Posted 24 July 2014 - 07:22 PM

 JacobPressures, on 24 July 2014 - 09:25 AM, said:


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.)


Yes, you understood it perfectly.

 JacobPressures, on 24 July 2014 - 09:25 AM, said:


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.


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.

Elisabeth
Elisabeth Robson
Co-founder, WickedlySmart.com
Author: Head First JavaScript Programming, Head First HTML5 Programming, Head First HTML and CSS, Head First Design Patterns
0

#3 User is offline   JacobPressures 

  • New Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 24-July 14

Posted 31 July 2014 - 09:18 PM

Thanks very much for taking the time to answer my questions! I greatly appreciate it.

Best wishes.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users