WEBVTT

00:00.120 --> 00:07.800
Hello again! In this video, we are going to look at classes and inheritance. When we are working with classes

00:07.800 --> 00:13.500
in programs, we often find there are some classes which are related, or represent similar concepts.

00:14.190 --> 00:18.480
For example, with graphical shapes, they will all have some position on the screen.

00:19.080 --> 00:21.660
We can draw them, we can fill them in with different colours.

00:22.080 --> 00:28.410
We can rotate them, and so on. With document elements, such as text, tables and diagrams,

00:28.950 --> 00:30.080
we can format these.

00:30.090 --> 00:31.830
We can move them around, we can zoom in.

00:33.780 --> 00:41.280
With input streams in the C++ library, we can process input from different sources and convert it to data.

00:42.600 --> 00:48.300
And we can use a class hierarchy to express these relationships between different classes, and make

00:48.300 --> 00:50.160
it easier to reuse code between them.

00:53.640 --> 00:59.700
So, for example, with our shapes, we could have a basic shape, and then some more specialized shapes

00:59.700 --> 01:01.560
like circles, square and triangle.

01:01.920 --> 01:04.800
So this is a hierarchy of shape classes.

01:07.280 --> 01:08.040
For input

01:08.060 --> 01:14.120
streams, we can have istream as the basic input stream, and then ifstream is specialized for working with

01:14.120 --> 01:18.590
files, and istringstream is specialized for working with strings.

01:21.540 --> 01:27.570
In computer science, trees have their roots at the top and class hierarchies have their base at the

01:27.570 --> 01:27.870
top.

01:28.170 --> 01:33.660
So the class at the top of the hierarchy - the shape or the istream - is called the base class.

01:37.100 --> 01:43.430
So the base class is the most generic or basic version. The classes which come below this are known as derived

01:43.520 --> 01:45.920
classes, or subclasses of the base class.

01:46.610 --> 01:50.480
We say that they "inherit from" the base class or are "derived" from it.

01:51.020 --> 01:56.840
And these are more specialized versions of the base class, or classes which have more features. Enhanced

01:56.840 --> 01:57.410
versions.

01:59.130 --> 02:03.930
With shape, we have circle, triangle, square, which are derived classes from shape.

02:04.530 --> 02:06.870
So these are all specific kinds of shape.

02:08.350 --> 02:13.390
For istream, we have ifstream and istringstream, and these are more specialized input streams.

02:17.490 --> 02:22.620
The relationship between the classes at the different levels in the hierarchy is called inheritance

02:23.430 --> 02:29.880
in terms of object modelling, this represents an "is-a" or "is-kind-of" relationship between the classes.

02:30.660 --> 02:34.800
So an istringstream is a kind of istream, and a circle is a shape.

02:35.850 --> 02:37.410
Okay, so that is it for this video.

02:37.800 --> 02:40.860
I will see you next time, but until then, keep coding!
