Java Reference
In-Depth Information
tation.IntheCoadandYourdonnotation,abstractclassesareidentified
byadashedrectangle.
A classification example
Supposeyouweretocreateasoftwaresystemforapetshop.Thepetshop
solddogs,cats,andbirdstothepublicandhadtokeeptrackoftheinven-
toryoftheseanimals.Anobject-orientedapproachtotheproblemcouldbe
basedoncreatinganabstractbaseclasscalledPet.Thenotionofapetclass
isanabstractionandtheclassPetwouldbeimplementedasanabstract
class.TheconcreteclasseswouldbenamedPetDog,PetCat,andPetBird.
ThePetclasswoulddefinetheinterfaceforitssubclasses.Therewouldbe
amethodcalledGetName()thatreturnsthenameoftheindividualpetani-
mal.AnothermethodcalledGetPrice()returnsthesalepriceofthepet,and
amethodcalledGetLocation()returnsthelocationinthepetshopwherea
specificanimalcanbefound.Tokeeptrackofpetnames,locations,and
pricesyouwouldneedthreevariables.Theresultingsystemwouldappear
asin Figure14-5 .
Inrelationtotheclassdiagramin Figure14-5 , notethefollowing:
The association between the superclass Pet and the subclasses PetDog,
PetCat, and PetBird is an is-a-kind-of relationship. The class structure is of
type Gen/Spec. The sem-circular connector in the class diagram shows the
Gen/Spec association.
Pet
petName
petLocation
petPrice
GetName()
GetLocation()
GetPrice()
PetDog
PetCat
PetBird
GetName()
GetLocation()
GetPrice()
GetName()
GetLocation()
GetPrice()
GetName()
GetLocation()
GetPrice()
Figure 14-5 A Pet Store Class System
 
Search WWH ::




Custom Search