Java Reference
In-Depth Information
Supposeyouwerecreatingasoftwaresystemthathadtokeeptrack
andmodelvariousdogs.Youcouldstartthedesignbycreatingaclass
namedDog.EachobjectoftheDogclasswouldhavecertainspecificat-
tributes,suchasaname,color,andweight.Also,theobjectsoftheclass
Dogwouldhavetheabilitytobarkandjump.Usingtheclassdiagramwe
couldmodeltheclassDogasshownin
Figure14-3
.
Dog
name
weight
color
Bark()
Jump()
Figure14-3ModelingtheDogClass
Inmodelingclasseswenotethattherearetwobasictypesofclassas-
sociations.Inonecase,thesubclassis“akind-of”theparentclassandin
anothercasethesub-classis“apart-of”theparent.Supposeyouuseda
classnamedPhysicianandaclassnamedSurgeontomodelamedicalsys-
tem.InthiscaseyoucouldsaythataSurgeonis“akind-of”aPhysician.
Ontheotherhand,ifyouweremodelinganautomobileusingaclass
namedEngineandanotherclassnamedStarter;inthiscase,therelation-
shipbetweenclassesisthatStarteris“apart-of”Engine.
The“kind-of”associationismoreproperlynamedageneralization-spe-
cializationrelationship(Gen/Specforshort).Part-ofassociationiscalled
aWhole/Partstructure.IntheCoadandYourdonnotationforclassasso-
ciations,theGen/Specrelationshipisshownusingasemicircletocon-
nectthesubclassestotheparentclass.TheWhole/Partassociationis
shownusingatriangletoconnectthesubclassestotheirparent.Theno-
tationcanbeseenin
Figure14-4
.
Figure14-4
showsabaseclassPhysicianthathasthesubclassesSur-
geonandPediatrician.Inthiscase,thesubclassesSurgeonandPediatri-
cianarespecializationsofthebaseclassPhysician.Ontheright-hand
sideof
Figure14-4
wehaveaclassAutomobileandthesubclassesChas-
sis and Engine. Here the classes Engine and Chassis are parts of the
whole, represented by the class Automobile. Therefore, the class associa-
tion is a Whole/Part structure and the subclasses are “a part-of” the super-
class.