Java Reference
In-Depth Information
hereweareusingthecommonmeaningoftheword“class,”notinthesense
ofaJavaclassstructure.Usinginheritance,knowledgeisorganizedintohi-
erarchiesbasedonclassrelationships.Thus,wesaythatanindividualin-
heritsthepropertiesoftheclasstowhichitbelongs.Forexample,animals
breathe,move,andreproduce.Ifthesubclassbirdbelongstotheanimal
super-class,thenwecandeducethatthemembersofthebirdclassbreathe,
move,andreproducesincethesepropertiesareinheritedfromitsbase
class.Scientificclassificationsarebasedoninheritanceofproperties. Fig-
ure14-1 isaninheritancediagramforsomeclassesofanimals.
breathes
ANIMAL
moves
reproduces
flies
swims
BIRD
FISH
has feathers
has scales
sings
CANARY
is yellow
Figure14-1ClassInheritanceDiagram
Classinheritanceisusedinknowledgebasestoensurethehighestlev-
elsofdataabstraction.Supposeyouarecreatingaknowledgebaseabout
birds.Thisknowledgebasestartsbydefiningthetraitsthatarecommon
toallbirds.Forexample,allbirdsflyandhavefeathers.Thenitdefines
thetraitsoftheparticularbirdspecies.Thecanaryisyellowandsings.
Therobinisredandmigratesinthewinter.Theresultisthatthesub-
classes,canaryandrobininthiscase,inheritthepropertiesoftheirpar-
entclass,bird,whichinturn,inheritsthepropertiesofitssuperclass,
animal,andsoon.Theresultisthattheknowledgebaseisreduced,since
commonpropertiesareassertedonlyonce.Inheritancestructuresalso
servetomaintaintheconsistencyoftheknowledgebase.
Object-orientatedsystemsuseinheritancesothatsubclassesacquire
thepublicmembersoftheirparentclasses.Hereagain,inheritancepro-
motesthehighestlevelofabstractionandsimplifiestheknowledgebase.
Itallowstheprogramdesignertobuildaclasshierarchythatgoesfrom
themostgeneraltothemostspecific.Applyingobject-orientationtothe
classdiagramin Figure14-1 ,wecansaythatANIMAListhebaseclass,
and that BIRD, FISH, and CANARY are derived classes. A derived class in-
 
Search WWH ::




Custom Search