![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
To gain insight into how classes, instance variables, and methods work together, you should draw a class-hierarchy diagram, such as the following:
*--------------------------------------* | Object | *--------------------------------------* | | subclass v *--------------------------------------* | Food | | Instance variables Methods | | fCalories fCalories | | cCalories fCalories: | | pCalories cCalories | | cCalories: | | pCalories | | pCalories: | | tCalories | | isVegetable | *--------------------------------------* | | | | | | subclass | | *-----------------------------------------------------* | | subclass | | *--------------------------* | | subclass | | v v v *----------------------------* *----------------------------* *--- | Vegetable | | Dairy | | | Methods | | | | | isVegetable | | | | *----------------------------* *----------------------------* *-- | | | | | | | | | instance | | | | | | | v v v v *--------------* Other Various | a Vegetable | Vegetable Dairy *--------------* instances instances
Such a class-hierarchy diagram helps you to see how to distribute instance variables and methods among the classes in the hierarchy.