Tuesday, 2 November 2010

Chapter 8 8.1-8.6


Barnes and Kolling Chapter Eight Questions
Barnes and Kolling Chapter Eight Questions


1
Open the project dome-v1. It contains the classes exactly as they were discussed in the text.
Create some CD objects and some video objects.
Create a database object.
Enter the CDs and videos into the database, and then list the database contents.

 Done, here's the printed terminal:

2
Try the following.
Create a CD object.
Enter it into the database.
List the database.
You see that the CD has no associated comment.
Add a comment to the CD object on the object bench (the one you entered into the database).
When you now list the database again, will the CD listed there have a comment attached?
Try it. Explain the behavior you observe.

 The comment part of the CD class is a field, and all the lsit() method does, in the database class, is print all the object fields.
3
Draw an inheritance hierarchy for the people in your place of study.
 Done:

4
Open the project dome-v2. This project contains a version of the DoME application rewritten to use inheritance, as described in the text.
*Note that the class diagram displays the inheritance relationship.
Open the source code of the Video class and remove the "extends Item" phrase. Close the editor.
What changes do you observe in the class diagram?
Add the "extends Item" phrase again.

 It won't compile, because the class relies on many of the super-class methods to function. Also, if it would compile, it would still lack all the methods it shares with the CD class that were put into the parent class.
5
Create a CD object.
Call some of its methods.
Can you call the inherited methods(for example setComment())?
What do you observe about the inherited methods?

 They work just as they do with the methods inside the class, it's as though there's no difference, only to select and call the method one must right click the object and go to a list of "inherited from Item" methods.
6
Set a breakpoint in the first line of the CD class's constructor.
Then create a CD object. When the debugger window pops up, use Step Into to step through the code.
Observe the instance fields and their initialization.
Describe your observations.

 When the instance fields get initialized the process goes into the Item class to find the code needed to initialize the fields, and returns the CD instance with the required information, the field value.

No comments:

Post a Comment