Classes can model things that can be concrete or abstract Truck Weight Fuel type Length Height Drive Stop Etc Fire Truck Truck Weight Fuel type Length Height Drive Stop WaterCapacity ID: 934625
Download Presentation The PPT/PDF document "Inheritance CSCE 121 Recall" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Inheritance
CSCE
121
Slide2Recall
Classes can model things that can
be concrete or abstract.
TruckWeightFuel typeLengthHeightDrive()Stop()Etc.
Slide3Fire Truck
Truck
Weight
Fuel typeLengthHeightDrive()Stop()WaterCapacitystartSiren
()
stopSiren
()
Add to truck class?
Slide4Concrete Truck
Truck
Weight
Fuel typeLengthHeightDrive()Stop()WaterCapacitystartSiren
()
stopSiren
()
cubicFeetConcrete
Pour()
So every truck could “
startSiren
()”???
So we include members for all types of trucks?
Add to truck class?
Slide5Separate Classes?
Truck
Weight
Fuel typeLengthHeightDrive()Stop()
Fire Truck
Weight
Fuel type
Length
Height
Drive()
Stop()
WaterCapacity
startSiren
()
stopSiren
()
Concrete Truck
Weight
Fuel type
Length
Height
Drive()Stop()cubicFeetConcretePour()
And more…
Slide6Separate Classes?
Truck
Weight
Fuel type
Length
Height
Width
Drive()Stop()
Fire Truck
Weight
Fuel type
Length
Height
Drive()
Stop()
WaterCapacity
startSiren
()
stopSiren
()
Concrete Truck
WeightFuel typeLengthHeightDrive()Stop()cubicFeetConcrete
Pour()
How many updates???
Share what’s
common?
Slide7Truck
Weight
Fuel type
LengthHeightWidthDrive()Stop()Separate Classes!
Fire Truck
WaterCapacity
startSiren
()
stopSiren
()
Concrete Truck
cubicFeetConcrete
Pour()
Share what’s
common!
Slide8Truck
Weight
Fuel type
LengthHeightWidthDrive()Stop()Inheritance
Fire Truck
WaterCapacity
startSiren
()
stopSiren
()
Concrete Truck
cubicFeetConcrete
Pour()
Add to an existing class!
REUSE!!!
Truck
AND
Fire Truck
Truck
AND
Concrete Truck
Slide9Some Terminology
Base / Parent
Derived / Child / Sub-Class
Slide10Access Permissions
Public
Private
Protected
10
Public members
Protected members
Private members
All code
Derived class’s members
Class’s own members
Slide11UML Updates for Inheritance
Permissions
+ Public
- Private# Protected
Slide12UML Updates for Inheritance
Relations
Association
AggregationCompositionInheritanceNavigability
concept of easy access from one to another
Many
One
Base / Parent
Derived / Child
Access to
Access from
Composite Object
Part of
Slide13Truck UML Class Diagram
Truck
-weight
#
fuelType
-length
-height
-width
+drive()
+stop()
Fire Truck
-
waterCapacity
+
startSiren
()+stopSiren
()
Concrete Truck
-
cubicFeetConcrete
+pour()
Slide14Instance of a Fire Truck, i.e. Fire Truck Object
Truck
-weight
#
fuelType
-length
-height
-width
+drive()
+stop()
Fire Truck
-
waterCapacity
+
startSiren
()+stopSiren
()
It is both
a Truck
AND
a Fire Truck!