Lecture 4 inheritance , polymorphism.pptx

hillarykiprono4 9 views 20 slides Oct 01, 2024
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

Explains on the object oriented programming in c++ inheritance polymorphism and other types of object oriented programming


Slide Content

Inheritance

Introduction Generalisation & Inheritance What happens when inheritance takes place? Multiple Inheritance Abstract Classes

Generalisation(1) Also known as inheritance Car Lorry Vehicle

Generalisation(2) Student Lecturer Module * 1 * * teaches attends StudNumb Title ModNumb Person Name

Inheritance Example(1) Consider these objects Red Car Yellow Truck Blue Car Green Truck

Inheritance Example(2) We can see that there are two car objects and two truck objects Therefore two classes ... Car Truck

Common & Different Data But Cars and Trucks have similar attributes (and functions) ... Car Truck TopSpeed Length Weight Colour BootVolume TopSpeed Length Weight Colour FlatBedSpace

Data Allocation Car Vehicle Truck float BootVolume float FlatBedSpace float TopSpeed float Length float Weight String Colour

Superclasses and subclasses A class defined in terms of another. SuperClass Subclasses

An Inheritance Tree Vehicle Car Truck SportsCar Hatchback Articulated Fixed Wheel Base 2 axle 3 axle

Data Attribute Location(1) Vehicle Truck Vehicle Truck float length float weight float length float weight float maximumLoad

Data Attribute Location(2) Truck Fixed Wheel Base Truck float length float weight float maximumLoad FixedWheelBase float length float weight float maximumLoad

Data Attribute Location(3) Fixed Wheel Base 2 axle 3 axle FixedWheelBase float length float weight float maximumLoad 3 axle float length float weight float maximumLoad int axleLoad

Inheritance Tree 3 axle Fixed Wheel Base Truck Vehicle A 3 axle truck is a Fixed WheelBase is a truck is a vehicle

Inheriting Data and Operations If the data or operation is missing in class try to inherit from higher level class. If the data or operation is present in class then use from this class.

Inheriting In Operation Person IncomeTaxCalc Student PayFees Holidays:=20 Lecturer Holidays:=35 SuperTaxCalc Holidays:= 100

Multiple Inheritance Vehicle FlyingBoat

Abstract Classes(1) Higher up inheritance hierarchy, classes become more general. They can become more abstract. An abstract class has no object instances.

Abstract Classes(2) Vehicle WaterVehicle LandVehicle AirVehicle Glider Plane Helicopter Balloon Rocket Abstract Classes

Conclusion Generalisation & Inheritance What happens when inheritance takes place? Multiple Inheritance Abstract Classes