
Object‐OrientedDesign&Patterns
Chapter6Questions
Revised10/31/2008
1. InheritanceandMultipleInheritance
a. Whatismultipleinheritance?
b. Whatpotentialproblemsdoesmultipleinheritancecreate?(pp.246f)
c. WhenshouldInoteuseinheritance?(pp.254f)
2. TheSubstitutionPrinciple
a. Statethesubstitutionprincipleandgivenanexampleofitsuse.
b. Whatproblemdoesthisprincipleattempttoavoid?
3. Pre‐conditionsandPostconditionswithInheritance
a. WhatmustIavoidwhendefiningapreconditionforasubclass?
b. WhatmustIavoidwhendefiningapostconditionforasubclass?
4. GraphicsProgrammingwithInheritance
a. Whatarethetwolistenerinterfacesforamouseevent?
b. Whyaretheretwolistenerinterfacesforamouseevent
c. Whatisthepurposeofthetwomouseadapterclasses?
d. UnderstandtheCar/Component/Moverexample.Youcanfindthecodeat
//ProfData/Grabow/csi3471/Workspace/car
5. AbstractClasses
a. Canyouconstructanobjectbasedonanabstractclass?
b. WhatisthebenefitofusingtheSelectableShapeabstractclassinthesceneexample?
c. Explainthesceneexampleusingtheclassdiagramonp.230.
d. Isitlegaltotaganyclassasabstract,evenifallofitsmethodsarealreadydefined?
Shouldyoudothis?
e. Canaclassextendmorethanoneabstractclass?Canaclassimplementmorethanone
interface?
f. CompareclassCarComponent(pp.226f)andclassSceneComponent(pp.232f)with
respecttotheirattributes.Whyisthereadifference?
g. WhatisthedefaultlayoutusedtocreatethebuttonsJPanelonp.234?
h. Executethescene3example(itslocationisthesameasthecarexamplementioned
above).WhatcodeexecuteswhenyouhittheRemovebuttonandthereisnothingto
remove?
6. TheTemplateMethodPattern
a. Whatproblemdoesthispatternaddress?
b. Describethenatureofthissolutionusingtheclassdiagramonp.237.
c. Howdoesscene2usethetemplatemethodpattern?
d. WhyandhowisCarShapeinthescene2exampledifferentfromCarShapeinthescene1
example?
7. ProtectedInterfaces
a. Whatisaprotectedinterface?
b. Howdoesscene3implementaprotectedinterface?
8. Later
a. TheHierarchyofSwingComponents
b. TheHierarchyofStandardGeometricShapes
c. heHierarchyofExceptionClasses