Java Reference
In-Depth Information
1.Eachpetisgivenaname,whichisrememberedinastringvariable.
2.Eachpethasasaleprice,storedinavariableoftypedouble.
3.Avariableoftypeintkeepstrackofthelocationofeachpetinthestore.The
petstoreshowroomislocation1,thebackroomislocation2,andthe
store'sbasementislocation3.
4.Thereisalsospecies-specificdatathatmustberemembered:thebreedof
eachdog,thebreedofeachcat,andthecolorofeachbird.
Sinceadogisakindofapet,andsoisacatandabird,youcanusein-
heritancetomodelthepetstoresystem.AbaseclassnamedPetcouldbe
usedtodefinethedataelementsthatarecommontoallthreepetspecies.
Sincethenotionofapetisanabstraction,theclassPetisdefinedasan
abstractclass.ThePetclassalsodefinestheinterfaceforthemethods
thatareimplementedinthesubclasses.Theclassdiagramforthepet
storeisshownin Figure16-4 .
Pet
petName
petLocation
petPrice
getName()
getLocation()
getPrice()
getSpecData()
Dog
Cat
Bird
catBreed
dogBreed
birdColor
getSpecData()
getSpecData()
getSpecData()
Figure 16-4 Class Diagram for the Pet Store System
 
Search WWH ::




Custom Search