background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "C++ #20 - polymorphisme"

input logo icon
Cover of audio
Please wait. We're preparing links for easy ad-free video watching and downloading.
console placeholder icon
Table of contents
|

Table of contents

0:00
Introduction
0:21
Qu'est-ce que le polymorphisme ?
1:02
Code d'exemple
2:59
Mise en place d'un héritage
5:38
Méthode virtuelle dans une classe
7:24
Redéfinition d'une méthode dans une sous-classe
10:43
Ajout de nouveaux types pour le polymorphisme
12:28
Accès aux attributs depuis une sous-classe
15:24
Fonctionnement du polymorphisme
20:37
Point sur le polymorphisme ad hoc
21:16
Appel d'une méthode de la classe parente
22:34
Classe abstraite
25:04
Méthode virtuelle pure
26:55
Quelle différence avec une interface ?
32:30
Conclusion
Video tags
|

Video tags

FormationVidéo
formation vidéo
cours
apprentissage
teaching
ordinateur
computing
cours en ligne
course
formation
informatique
tutoriel
tutorial
C++
CPP
polymorphisme
classe abstraite
interface
méthode virtuelle
virtual
cpp
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:15
hello In this session 20 of C++ we are
00:00:17
going to, as promised, address together the
00:00:19
concept of polymorphism the term
00:00:22
polymorphism simply means which
00:00:25
can take several forms and here we
00:00:27
program we know more more in
00:00:29
object oriented programming we will
00:00:31
refer to our different objects to
00:00:33
different classes finally which are
00:00:34
the different entities of our
00:00:36
application and which will be able to take
00:00:38
depending on the execution to make
00:00:42
them adopt in any case their own
00:00:45
behavior, that is to say that we will
00:00:46
provide a global interface for
00:00:49
all of these entities and then the
00:00:51
behavior will be specific to each so
00:00:53
regardless of their type we can
00:00:55
use this interface but we will
00:00:57
come back in detail of course especially these
00:00:58
different terms that we will see together as
00:01:00
the video progresses
00:01:01
for the example I changed a little bit
00:01:03
the code that we had previously which was
00:01:05
starting to be quite important for
00:01:06
in any case what I had to
00:01:08
present to you so I further reduced what we
00:01:10
are going to rewrite other little
00:01:11
things so I'll give you a
00:01:13
quick summary here we now have a class
00:01:15
without less to represent someone
00:01:17
quite simply I like I don't want to
00:01:19
allow the creation of a person
00:01:21
with a constructor by default it is
00:01:24
disabled so delete we have a
00:01:26
constructor simple which just requires a
00:01:28
name and a little method in fact to
00:01:30
say good night okay quite simply
00:01:32
so there by default you can see I
00:01:33
quickly show you that the an object
00:01:37
from this class someone and well
00:01:38
your simply say nothing s' will display
00:01:40
its name but we will have no
00:01:41
precise message it is something quite vague
00:01:43
and it will go very very well for
00:01:46
what I am going to explain to you concerning the
00:01:47
polymorphism here I simply make an
00:01:50
instantiation and I call the
00:01:52
method directly we will compile to
00:01:54
see that everything is good and then we will
00:01:55
move on as I explain
00:01:57
the different categories to you,
00:02:00
this is simply what we have
00:02:02
here
00:02:04
the goal of the polymorphism will be to be
00:02:06
able, as I told you, to provide a
00:02:08
global and generic interface to
00:02:10
all of our entities, that is to say
00:02:11
that we will allow for example if we
00:02:13
make several people talk so
00:02:16
here in this case make them say
00:02:17
good night quite simply
00:02:19
regardless of what they will
00:02:20
really be, we are agreement here I made
00:02:23
the arbitrary choice to designate
00:02:24
someone someone it's very vague we
00:02:26
don't really know someone it could
00:02:27
be almost anyone and we're going to
00:02:29
refer to people who would speak
00:02:31
in different languages, for
00:02:32
example not a French person, a
00:02:34
Japanese Indonesian English person,
00:02:36
etc. and from there adapt this
00:02:39
behavior as long as we can
00:02:41
make people speak
00:02:42
regardless of what they
00:02:44
really agree with, that is to say that we will be
00:02:46
able to create several instances of
00:02:48
someone and then call on their
00:02:51
method so then service then
00:02:52
functionality and you will see that it
00:02:54
will adapt completely to what they are
00:02:56
so the real type that it presents
00:02:59
so here we finally have the
00:03:00
static type okay it's the global type
00:03:02
the type a little bit we're going to say the
00:03:04
base type the base class that we have
00:03:06
here and we're going to be able to then create
00:03:08
other elements so we're going to make
00:03:09
one first one already which will be a
00:03:11
derived class so this is where
00:03:13
inheritance comes in what we are going to talk about here about
00:03:14
inheritance polymorphism be careful
00:03:17
not to mix with
00:03:18
Haddock polymorphism in particular which we had seen a
00:03:20
little previously with the overloading of
00:03:22
methods of functions is
00:03:24
something that also exists here we are
00:03:25
really talking about the polymorphism induced with
00:03:27
inheritance and therefore linked to
00:03:29
object oriented programming
00:03:32
we are going to make our element quite quickly
00:03:34
we will do copy and paste if necessary I
00:03:36
will then create I put that without me
00:03:40
so we're going to put it like that
00:03:43
English we're going I could put
00:03:45
much longer names but it will be
00:03:46
faster more practical
00:03:49
for the video it avoids having
00:03:51
black extensions too
00:03:53
and of course in normal times I 'would have put it
00:03:54
much more explicit than that
00:03:55
because there suddenly it's English but
00:03:57
English what English an English document
00:03:59
an English person we don't really know
00:04:01
[Applause]
00:04:07
I'm going to put the elements here it will be
00:04:09
more practical
00:04:12
I'll take this again
00:04:14
so that's 'is what will represent
00:04:16
no one in any case who speaks English
00:04:18
okay that's what I'm saying we
00:04:19
could have chosen a much
00:04:20
more precise class name much more explicit in
00:04:22
any case than simply English like
00:04:24
this but that will be fine very good I'm fine
00:04:27
we're not going to create here we can't redo
00:04:29
each time we're going to save a little bit of
00:04:30
a little bit of line here that doesn't interest us
00:04:34
for the moment we'll eventually see
00:04:38
what we do afterwards
00:04:44
even the name could have been English we
00:04:46
will see if eventually we remove it so
00:04:49
that it is a little lighter
00:04:52
here in English HPP this is what we
00:04:57
have so the goal here is we know
00:04:59
the statics the base class and we are going to
00:05:02
want to derive English from this
00:05:04
class month so here we go we have in place
00:05:07
this inheritance relationship to say well
00:05:09
that a person who speaks English and
00:05:11
ultimately a kind of someone is
00:05:13
someone so we can
00:05:15
perfectly understand this relationship of inheritance
00:05:16
that we have here so I make my
00:05:19
inheritance relationship as it is and
00:05:21
from there automatically
00:05:23
everything that is in someone with
00:05:25
the exception of the constructors
00:05:27
remember that you have to do the
00:05:28
transmission explicitly on them and
00:05:31
well we have all the elements that
00:05:33
we wanted subsequently in
00:05:35
particular here what is transmitted
00:05:38
from there
00:05:40
so what we have this element there
00:05:41
this class we are going to indicate that
00:05:45
this method is virtual
00:05:47
this is intended in fact so as to say
00:05:49
that At execution we will have to
00:05:52
think about looking a little further
00:05:54
in the
00:05:56
possible derivations of the classes rather than
00:05:58
finally being satisfied with this
00:05:59
base class to finally say someone
00:06:01
when they say good night we saw it
00:06:03
earlier in the execution it doesn't do
00:06:05
much we don't have it's too vague
00:06:07
it's we don't have enough information at
00:06:09
this level that interests us not in
00:06:10
itself we don't necessarily want to make people talk about
00:06:11
that, we simply use this class
00:06:13
as a common base for lots of
00:06:16
different people who will speak several
00:06:18
different languages ​​and yet we
00:06:20
want to make it possible afterwards to say
00:06:22
everyone say good night and so that
00:06:23
people can everyone say good night in
00:06:26
their own way in their own language
00:06:27
and that's the whole point once
00:06:28
again of polymorphyloyer it takes
00:06:30
several times it's the same service the
00:06:32
same interface that we distribute for
00:06:33
everyone on the other hand it's is independent
00:06:36
independent in fact of the real type of
00:06:39
each capacity that we have behind
00:06:40
so for me the real entity so a
00:06:43
real type we only have one we have this
00:06:45
type we will possibly make a
00:06:46
second one to see a little bit by the
00:06:47
rest so here we go here we will indicate
00:06:50
that the method is virtual with the
00:06:53
keyword virtual quite simply you
00:06:55
could have an implementation so
00:06:57
I specify that because in other
00:06:58
programming languages ​​when we have a
00:07:00
virtual or abstract element we can
00:07:01
use we eventually find the
00:07:03
keyword abstract we don't necessarily have
00:07:05
to implement it so it depends on
00:07:07
the languages ​​but know that it's
00:07:08
more because I have here for example
00:07:10
totally authorized I can have
00:07:11
the implementation of 'go an element which
00:07:14
is virtual okay I'm going to remove it
00:07:16
because once again here it has no
00:07:17
interest for the video at this stage we
00:07:19
can easily remove it but know that
00:07:21
the implementation is totally possible
00:07:22
there is no problem at this level
00:07:23
so I have my signature here okay and
00:07:27
then I'm going to use exactly the
00:07:29
same signature so that doesn't change
00:07:30
it's always the same it's what
00:07:32
I had here except that I will think about
00:07:34
adding the overright keyword
00:07:36
to say that we are redefining
00:07:38
the method, that means that it will not
00:07:41
call the implementation of this
00:07:43
method. Well, I removed it so there
00:07:44
is no risk but he could have
00:07:46
called this one by default but to say be
00:07:48
careful if it is an object an entity
00:07:50
of the class English you must call its
00:07:53
implementation hence the
00:07:54
redefinition and the fact of indicating it
00:07:56
explicitly with the word key overite
00:07:59
from there I take the whole
00:08:01
signature here
00:08:02
and we will write things directly
00:08:04
and see that there it will begin to
00:08:07
specialize thanks to the derivation that we
00:08:08
made with precisely this
00:08:11
inheritance relationship so everything at the same time time so
00:08:14
that finally I'm going to put it back a
00:08:15
sorry we just had that there we're going to
00:08:18
take the information here
00:08:21
and indicate there's no one who speaks
00:08:23
English she's going to be able to say things
00:08:25
her way
00:08:28
we're going to put a little point no don't
00:08:30
put a point d 'exclamation no
00:08:31
punctuation just stay like that quite
00:08:33
simply there he has his way of saying
00:08:35
things
00:08:37
we're going to leave that
00:08:40
OK
00:08:42
here we're going to
00:08:46
call directly on that
00:08:55
that's anyway there I'm going to be missing
00:08:57
an element because I'm going to
00:08:59
need
00:09:03
as I made badly pasted copies I
00:09:05
will probably have to add lines
00:09:15
well it's normal anyway it does
00:09:16
n't matter I will add them
00:09:18
again I am thinking mainly about what I am
00:09:19
telling you and not so much about file in head here
00:09:22
so that's it so this behavior of the
00:09:25
base class the static type it passes
00:09:27
what is really interesting for us what
00:09:28
interests us then is all
00:09:29
the derived titles that we are going to have so
00:09:31
we have that and subsequently I'm going to be able to
00:09:33
also
00:09:35
so we're going to do it
00:09:37
next as long as we make
00:09:45
the number bag in the name I could have
00:09:47
removed it we're going to keep it anyway
00:09:57
we're going to keep it here it will go very well
00:10:00
there I'm changing see what that I make
00:10:01
modifications we must not forget the half
00:10:03
and I must be able to say the same thing
00:10:04
so we have not yet seen a
00:10:06
destructuring of data of the containers
00:10:08
of the collections like the tables the
00:10:09
lists etc things that we will see
00:10:11
later in the course we don't do it
00:10:12
so necessarily here I'm going to have a bit
00:10:14
of code repetition I'm not going to go
00:10:15
through a loop for certain elements
00:10:17
because we're still missing quite a few
00:10:19
things I can't I put a whole
00:10:20
bunch back of objects in a single structure
00:10:22
but these are things that we will see
00:10:23
later so we can approach that at that
00:10:25
time so the goal is still
00:10:26
that for you is that you
00:10:27
understand this is that we must be able to
00:10:29
make different characters speak
00:10:31
once again afterwards independently of
00:10:33
what are there for the moment so
00:10:34
we use the real type directly but
00:10:36
you will see later the advantage that
00:10:38
it can have
00:10:40
so I normally have that c is good
00:10:41
[Music]
00:10:43
yes then we are obviously going to create the
00:10:45
new one
00:10:46
that goes without saying
00:10:53
so I do that right away before
00:10:54
recomposing anything
00:10:57
on my only one example we don't know it's
00:11:00
not much it still
00:11:02
seems like it's having a
00:11:03
little more specialization
00:11:07
and it's starting to make a lot of
00:11:08
files as I saw I zoom well for
00:11:10
the video
00:11:11
but we're going to put it there English we did it
00:11:15
here OK
00:11:20
[Applause]
00:11:21
I'm taking a little time to make all
00:11:22
the changes
00:11:24
here
00:11:26
he also
00:11:28
inherits from his monk redefined this
00:11:31
method okay so that doesn't change
00:11:35
and this is what we are going to do here
00:11:39
here he redefines and he does not
00:11:42
possibly say this to me the blade that's
00:11:46
like that we have the rediff finish which is
00:11:49
done here I think it's good for
00:11:52
the different files we're going to compile
00:11:53
already plus he made small
00:11:54
careless errors it's not worth
00:11:56
correcting them there it's missing maybe things
00:12:00
[Music]
00:12:06
ah yes I put it in the pardon I
00:12:07
have to put them in the definition that
00:12:09
's because of my copy and paste yes
00:12:10
obviously it's only for the definition
00:12:21
ok after we have another error but
00:12:23
it's normal I wanted her to be there to
00:12:25
talk to you about it which we hadn't
00:12:26
done previously so here we
00:12:28
have a first error you see on
00:12:30
the name tribe so there may be some being
00:12:31
an aura perhaps others we will see
00:12:33
later
00:12:35
but already I especially wanted us to
00:12:36
focus on here is the error concerning
00:12:39
the tribe name since we are simply telling you
00:12:41
that this attribute is private
00:12:43
okay and we are trying so to access
00:12:45
a private attribute from here it's
00:12:48
class there if you look in this month
00:12:50
okay this class that the tribe
00:12:52
actually with a private access level
00:12:54
so that means we explained
00:12:56
before that it is accessible directly
00:12:59
than by the class itself agree
00:13:01
within this cup there automatically
00:13:03
if I try to access this element
00:13:05
from the English class or from the
00:13:07
Indonesian class automatically it
00:13:09
does not work since they do not have this
00:13:11
accident we will therefore find a compromise
00:13:13
what the point is not to make it
00:13:15
public if we make the tribe public it
00:13:17
will therefore be accessible everywhere and we
00:13:19
absolutely do not want that so there is a
00:13:21
level of access between the two which is
00:13:22
protected protectide which simply
00:13:24
means that we make direct access possible
00:13:27
to the element where it of course modifies
00:13:29
the class which declared it and
00:13:32
it is under class so there we can
00:13:35
indicate because ultimately we a
00:13:37
that this element there for the touch and
00:13:39
automatically name becomes a
00:13:41
protected element which is also transmitted in any
00:13:43
case which is accessible directly for
00:13:44
the derived classes so there already we will
00:13:47
have cleared this error there so that's
00:13:49
when it will be introduces a
00:13:50
new keyword that we hadn't seen
00:13:51
until now and I think in any
00:13:53
case that we would almost have to see everything
00:13:55
that goes well afterwards they perhaps have
00:13:56
some elements for me because once again
00:13:58
I added quite a few things
00:14:06
knock knock knock
00:14:15
as I went along
00:14:19
I made a typo again
00:14:20
afterwards
00:14:24
so englishn what
00:14:27
change did I make we have to go back
00:14:29
through the manufacturer obviously
00:14:32
it goes without saying so we're going to come back here
00:14:37
[Applause]
00:14:44
I would actually like to avoid having to
00:14:45
write more code
00:14:49
so if we can directly just
00:14:50
transmit the constructors that would suit
00:14:51
me otherwise we will at worst remove
00:14:53
the tribe which I leave in management to
00:14:54
do that I write constructors
00:14:55
everywhere and once again it's
00:14:57
really not the subject so that will
00:14:59
pass but it's true that I would have liked all the
00:15:00
same which is less code less
00:15:02
code and less it's confused in fact
00:15:03
to explain concepts to you
00:15:05
so it goes without saying but in any
00:15:08
case here we still arrive at what
00:15:09
I wanted so it would be fine a
00:15:10
little ago there is a little more code than
00:15:11
what I would like but it doesn't matter
00:15:12
all you see in any case is
00:15:14
that here Jacques who is in who speaks
00:15:16
in English expresses himself in his language
00:15:18
of agreement and Bounda who is Indonesian
00:15:21
expresses himself in his language also
00:15:22
independently so as it could be
00:15:26
said in fact it is logical in any
00:15:27
case they each have their own method as it is so in
00:15:29
fact there we could even turn
00:15:30
without a monk it would work as it
00:15:32
would work in fact as it is
00:15:34
done here d 'Okay, the someone here has no
00:15:36
use
00:15:37
if we do all that, the difference will
00:15:40
be made especially when we are going to manipulate
00:15:42
people, here are English
00:15:44
or Indonesians, but
00:15:47
people of this type, that is to say
00:15:49
that by continuation and that we will see well
00:15:51
when we approach the
00:15:52
data structures the containers etc rather to
00:15:54
voluntarily create in fact this type of
00:15:56
person we can have a
00:15:58
data structure for example a list of two
00:16:00
people so we will make a list of
00:16:02
someone and in this list we can
00:16:05
put all the people who derive
00:16:07
from this type because remember that this
00:16:09
is the basic type we can put
00:16:11
both English and Indonesians
00:16:13
why not later allow us
00:16:15
to add French from add here are
00:16:16
Japanese people from all
00:16:19
different countries and then via a simple
00:16:22
loop since we will have an element a
00:16:24
complete structure we can say well in
00:16:25
fact for all the people on the
00:16:27
list well you say good night
00:16:30
okay and that's 'will
00:16:31
automatically then adapt behavior to
00:16:34
their type it will not in fact call on
00:16:36
a type
00:16:37
a generic method since everyone
00:16:39
will have redefined their own method and therefore their
00:16:42
way of saying good night and that is
00:16:44
once again the whole point of
00:16:45
polymorphism famous take
00:16:46
several forms of agreement so that's
00:16:48
all the interest that it will have so we will
00:16:50
simply do we will make a list a
00:16:53
table whatever the type of that less
00:16:56
there and then what we will say
00:16:59
if I write down quickly it is not even an
00:17:01
algorithm but it's more fries we
00:17:04
will say here we are going we will declare
00:17:10
etc of without monk OK
00:17:14
in which we will obviously put
00:17:18
initialize therefore
00:17:21
several derived objects
00:17:24
[Applause]
00:17:28
OK and then we will say for each
00:17:32
be me therefore each person in makes
00:17:34
the list of the table
00:17:41
call the
00:17:44
good night method
00:17:46
quite simply
00:17:48
and it will adapt
00:18:30
otherwise if
00:18:34
[Applause]
00:18:40
I think you are starting to understand
00:18:41
here is the problem which would have to do
00:18:44
this we would have a lot of checks
00:18:45
to do to check in made of what type
00:18:47
of class and an object of agreement a stance
00:18:50
of what and especially the day you
00:18:52
want to add it you must rewrite
00:18:54
all your code and let's admit that you
00:18:56
use methods which require for
00:18:58
example to pass a type
00:19:00
of information like well you want
00:19:01
to use functionalities for the
00:19:03
English it's not generic that is to say
00:19:05
that the day you want the
00:19:07
Indonesians to be able to do the same thing
00:19:08
you will have to write a second
00:19:10
method you will have to make sure to
00:19:11
check what you pass if it's an
00:19:13
English again it will do this if it's an
00:19:16
Indonesian it will rather do this and you
00:19:17
don't have generic code whereas
00:19:19
operating under a common type which is
00:19:21
this and having a method then
00:19:22
who says well me in fact it doesn't matter what
00:19:24
type of person I have and well
00:19:27
here I am he will be able to do
00:19:28
something because he will have redefined his
00:19:30
own behavior and polymorphism
00:19:32
that's what it's really about taking
00:19:33
several forms we finally have a deduction
00:19:35
of the behavior to be taken at
00:19:37
execution a dynamic resolution and
00:19:39
independently of everything else it is
00:19:41
much easier to evolve the
00:19:43
code as it is we can add once
00:19:45
again you see people in our
00:19:46
country without necessarily breaking the code that we
00:19:48
will have existing so once again
00:19:50
we don't really have this gymnity at
00:19:53
this stage since we haven't yet
00:19:54
seen the containers, in particular the
00:19:56
tables, we haven't yet seen the
00:19:58
tables I think that this is what we
00:19:59
will see in any case perhaps at the
00:20:00
next session or after and with that
00:20:03
you will see that it will be much
00:20:04
easier because we are not going to
00:20:05
directly declare here this we are creating a
00:20:08
table of that since you know that one
00:20:10
here you will necessarily have to create a
00:20:11
container of a single type so if we create
00:20:13
a table of or a list of English
00:20:15
you cannot put Indonesian with
00:20:17
them it is not possible whereas
00:20:19
using the basic type the common type
00:20:20
as it brings together they bring together
00:20:22
several different types and well there
00:20:24
you can mix the people and that
00:20:26
makes a word a world much higher
00:20:28
so it's wonderful that's quite
00:20:29
simply
00:20:31
ok let's continue we're going to move forward a a little
00:20:33
bit of what we have we still have a lot of
00:20:35
things to say in any case about that
00:20:37
so you can't do what we did
00:20:38
earlier it's the same I
00:20:39
quickly talked to you again about
00:20:41
Haddock polymorphism or you cannot do it
00:20:42
at the level of inheritance polymorphism
00:20:43
i.e. here I have an
00:20:46
agreement signature for my method here in a
00:20:50
derived class I cannot change
00:20:51
this signature for example here if
00:20:53
I had one I don't know here I had
00:20:55
an int parameter an integer I can't
00:20:58
suddenly make it a double this type
00:21:00
so overloading is this number 6
00:21:01
Madoc is not possible okay in
00:21:03
this case that does not work so
00:21:05
be careful there are rules like
00:21:07
that things which are prohibited and
00:21:09
which you cannot absolutely apply here so you have to keep
00:21:12
all that in account
00:21:15
ok what we can do small little
00:21:19
interesting side also for information
00:21:20
let's say that he actually is Indonesian we
00:21:23
want him to call here because we
00:21:25
had an implementation the method of
00:21:27
the class per year the base class you
00:21:28
can from a subclass
00:21:30
call a method of the parent class
00:21:32
it is enough to refer to this
00:21:34
class in question we could
00:21:36
even do both that is
00:21:37
to say that there well I am not going to
00:21:38
delete this code yeah I am going to
00:21:39
comment it all the same and I could very
00:21:41
well say you call since without a monk
00:21:44
with the scope resolution operator
00:21:47
its own method and there naturally we
00:21:51
will in fact have the call to this method in
00:21:53
question so that is important since
00:21:54
a daughter class call a
00:21:56
method of the class by an you
00:21:58
use the name of the class in question
00:21:59
the scope resolution operator you
00:22:01
see that suddenly bah Bunda who is
00:22:03
Indonesian behaves when she says
00:22:04
good night like that one here like
00:22:06
someone on vacation her steps in fact
00:22:08
finally what language she speaks she
00:22:10
is mute she doesn't say anything so that's
00:22:12
a little bit like that how to
00:22:14
send these different behaviors
00:22:16
that we can adapt and of course good if
00:22:17
I had left the line below it
00:22:19
would have done both that goes without saying
00:22:21
first time where she actually says the
00:22:23
same thing as someone and then she
00:22:24
says she does her own treatment so
00:22:27
she actually says her own sentence
00:22:28
so there she expressed herself twice and
00:22:30
it works very well too
00:22:33
ok we are going to go a little further with a
00:22:36
concept, well a continuation in any case of
00:22:38
these concepts and which
00:22:42
is a little bit different in fact we know
00:22:43
more and compare other languages ​​if
00:22:45
you do Java of Peyton of
00:22:46
javascript etc or PHP these are
00:22:49
concepts which change quite a bit notably
00:22:51
what we call abstract classes
00:22:54
where the interfaces there are no
00:22:56
more keywords to create
00:22:59
define these two things okay you
00:23:01
don't can't declare that a class is
00:23:04
abstract abstract sorry can't
00:23:05
do this in the it doesn't exist it's
00:23:07
more and we can't create
00:23:09
an interface either so say but if without
00:23:11
monk it becomes an interface
00:23:14
for all that we can make sure at the
00:23:17
code level at the
00:23:18
planting level and although it is all
00:23:20
like it really works all the same
00:23:22
and you will see how
00:23:24
an abstract class still already we know
00:23:27
more the more there is no
00:23:28
real difference in itself between an interface an
00:23:31
abstract class thing which differs in
00:23:33
a language which applies both if in
00:23:35
a language I am thinking of there for example
00:23:37
PHP you can have both there are
00:23:39
other languages ​​like that you have
00:23:40
abstract class and interface in Java
00:23:43
also in particular there is indeed a
00:23:44
difference between the two, it doesn't matter
00:23:46
much but there is still a
00:23:47
difference here we don't know anymore, in
00:23:49
reality we could say that there is
00:23:51
n't one even if you will see that it
00:23:53
quibbles a little we can still
00:23:54
finally say to ourselves well an interface is
00:23:56
rather this an abstract class we know
00:23:58
more it is rather these eventually
00:23:59
I will show you the small
00:24:01
subtle difference that we can make between inside
00:24:04
it is more more but in terms of
00:24:05
agreement syntax at the level of the lexicon of the
00:24:06
language anyway there are no
00:24:08
key words to indicate this it is
00:24:09
abstract and this is an interface we
00:24:12
know more the more it does not exist so
00:24:14
how to produce how to reproduce the
00:24:16
behavior of an abstract class
00:24:17
ultimately and of an interface so for
00:24:19
those who do not already understand in
00:24:21
other programming languages ​​when we
00:24:23
refer to these two terms
00:24:24
so that stresses me out it is a class
00:24:25
which is too vague here it is is
00:24:27
abstract we will therefore never be able to
00:24:28
instantiate it we will not be able to create
00:24:30
objects instantiated from objects of this
00:24:33
class here in this case it would be a
00:24:35
good idea to say to ourselves well in fact we
00:24:36
can never create someone because that
00:24:38
someone well it's nothing yes we are
00:24:40
not as much as someone in the world we
00:24:42
necessarily come
00:24:43
from a country we were born somewhere we
00:24:45
speak a language at least that's it we
00:24:47
necessarily come from somewhere so say to yourself
00:24:49
that you can't create someone, I do
00:24:52
n't know, I'm someone who comes from I
00:24:53
don't know where it could ultimately be logical
00:24:54
to say that this
00:24:56
base class is abstract, okay, it does
00:24:58
n't represent something concrete
00:24:59
it's not precise enough it's
00:25:01
too vague and we could do this
00:25:04
then plus more to have an
00:25:07
abstract class you need at least one of the
00:25:10
methods that you have at least one at
00:25:12
least it can be all that can to be
00:25:13
two three million must at least one
00:25:15
be declared pure virtual
00:25:19
here you have a virtual method
00:25:21
only
00:25:23
to obtain a pure virtual method you just
00:25:27
have to do this the 0 it's a
00:25:30
bit what represents it's plus plus the
00:25:31
null value of agreement when we decrease in
00:25:33
fact we no longer use the
00:25:34
macro in C++ in capital letters which is
00:25:37
reserved in particular for the C language we
00:25:39
rather use the 0 this means that
00:25:42
this method is a
00:25:44
pure virtual no function and as there are at
00:25:47
least only one well here you can
00:25:48
say that someone class
00:25:50
is an abstract class
00:25:54
however this is the particularity if
00:25:57
you are used to programming in
00:25:58
other programming languages ​​which
00:25:59
use the object paradigm this does
00:26:03
not prevent you from doing so. 'also implement a
00:26:05
pure virtual method we know more the more you
00:26:07
can do it yes that does a lot of
00:26:08
things that in other languages ​​we
00:26:09
absolutely couldn't that's it from
00:26:11
the moment anyway we have
00:26:12
something in an interface an
00:26:13
abstract class so an abstract element we
00:26:16
cannot implement it and then when
00:26:18
it is pure we should even less but
00:26:19
in C++ you can still but that is
00:26:22
not really what interests us
00:26:23
once again here the interest is to
00:26:25
reproduce a little this behavior of
00:26:26
saying to ourselves we are not in any case
00:26:28
necessarily systematically trying to implement
00:26:30
that so here I am removing it because I believe
00:26:32
that making someone speak does
00:26:35
not make sense, okay in this case I
00:26:37
'm never actually going to directly make
00:26:39
someone talk, we're going to make
00:26:41
other people talk who are once
00:26:43
again derived from someone but who have
00:26:46
their behavior, their own type and
00:26:47
their real type here it only remains one
00:26:50
type static so it is really the
00:26:52
basic type and in this case here the
00:26:53
type
00:26:55
so how is the difference made with
00:26:56
the interface you said that there is
00:26:57
not already and we do not
00:26:58
syntactically find the principle of
00:27:00
abstract class or interface we don't know anymore
00:27:02
there are no keywords for these things
00:27:04
and there is not really a difference
00:27:06
between the two in reality you could
00:27:08
say that there is one
00:27:10
it is appropriate for developers to
00:27:11
say when it's more plus bah an
00:27:14
abstract class finally becomes an
00:27:15
interface or can be named like that when
00:27:17
all these methods are
00:27:19
pure virtual in fact it's all the
00:27:21
virtual methods that you have are marked
00:27:22
pure so are in fact completed and
00:27:25
finished with a equal 0 you can estimate
00:27:27
that this is the case good there I have my
00:27:29
constructor OK and there if I only have
00:27:32
pure virtual methods we can
00:27:33
say that it becomes an interface and an
00:27:35
interface what is it is
00:27:36
once again in other languages ​​it is a
00:27:38
contract that is to say that you indicate
00:27:41
a list of functionalities agreement
00:27:44
then it is even a functionality in
00:27:45
itself at the interface but it can
00:27:46
contain several methods not
00:27:48
necessarily because what we call a
00:27:49
pure interface in particular is often
00:27:51
an interface which has only one
00:27:53
method of agreement it exists so do
00:27:55
n't be shocked if one day you
00:27:56
encounter that but it is once again
00:27:58
it depends on the naming of the
00:28:00
programming languages ​​and from there if a
00:28:03
class implements an interface in
00:28:05
other programming languages ​​it
00:28:07
has the obligation to redefine all the
00:28:09
methods of the interface
00:28:10
so if you have declared an interface
00:28:12
which has 5 methods of agreement another
00:28:16
class which implements it must create
00:28:18
write the code implement these 5
00:28:21
methods there we know more the more you
00:28:22
understand that it is different what I
00:28:24
told you that we can do the implementation of virtual method we
00:28:26
can implement a
00:28:27
pure virtual method so once again we
00:28:29
could we do not necessarily have the
00:28:31
guarantee of seeing to say we are
00:28:34
always obliged to go through something else
00:28:35
however we will still have to define
00:28:37
redefine things here 'elsewhere what
00:28:40
I can do because there I
00:28:41
passed it as is I removed the code here
00:28:45
I'm going to remove it for English
00:28:47
here
00:28:50
I have it removed here too so English
00:28:53
no longer has not redefined the method 7
00:28:55
good night you see here we could
00:28:58
say after all as English is a
00:28:59
kind of someone it does not get
00:29:02
worse if the compiler does not find a
00:29:04
method that it has defined it will call
00:29:06
the method the class per year since in
00:29:07
Normally this is how it would
00:29:08
happen so it should work we
00:29:10
compile
00:29:13
and there automatically we will see the
00:29:14
problem that it will pose since we are going to
00:29:16
change the behavior that we have
00:29:17
here we see that our Dick Rivers
00:29:24
so already we will we cannot be rigorous about
00:29:27
this error, we don't care but
00:29:29
above all that's what will bother us
00:29:31
is that here we have an element which is
00:29:33
virtual and we will have to in fact we said
00:29:36
that it is very pure and we're going to have to
00:29:37
really implement it so we have to
00:29:39
implement that since it's
00:29:42
pure virtual we really have an
00:29:44
abstract class here so here's an
00:29:47
abstract class or an interface if
00:29:49
you want you can once again
00:29:50
it's more accurate there you can
00:29:51
consider that the two are the same
00:29:52
so we can quibble to find a
00:29:54
difference but in reality it is the same
00:29:56
thing so we will see that and I will
00:29:59
put back my implementation we will
00:30:00
put back as before obviously to
00:30:02
indicate that here we were obliged to
00:30:04
redefine things so that it works and
00:30:06
which has no more problems
00:30:07
so you see we really have these
00:30:09
differences there I have a little
00:30:12
errorsomeone
00:30:16
ah yes because yes I was appealing
00:30:17
in Indonesia here obviously we
00:30:19
can more there are more it no
00:30:20
longer exists this method it's finished there
00:30:23
so I compile everything is fine I just
00:30:25
forgot to remove this little
00:30:26
instruction
00:31:29
declare the virtual element so we can
00:31:31
directly write the destructor
00:31:35
so besides I can even put in
00:31:37
to 0 in fact because in fact it's
00:31:42
I'm going to get there and like that you
00:31:45
actually have the elements for if you
00:31:47
want to transmit the whole thing and
00:31:50
the responsibility to the other classes in
00:31:52
any case we don't have yet seen a
00:31:53
resource manager we have
00:31:56
n't yet spoken at this stage we still have
00:31:57
a lot of things to see we don't know
00:31:58
anymore but all that once again there are
00:32:00
perhaps things that are not very
00:32:02
clear you don't you may not see in
00:32:04
practice what that implies but
00:32:06
as you progress,
00:32:07
as you learn
00:32:08
to sign things you will
00:32:09
understand more and more the interest of all
00:32:11
the things that we we saw from the beginning in
00:32:13
fact to the end of the course really gradually
00:32:15
that's good I'm going to remove this
00:32:17
once again it's more for that but know that
00:32:18
if afterwards you want to do
00:32:20
correct code you will have to follow a little
00:32:22
these different rules and try to
00:32:23
do things properly but here we are
00:32:25
mainly going to limit the line name so
00:32:26
that there is not too much code for
00:32:29
what I have explained to you here
00:32:31
so I already hope that all this is clear
00:32:32
okay we talked about the
00:32:35
transmission of information with this
00:32:36
key word for tactile we
00:32:38
of course came back to the inheritance relationship
00:32:42
itself the fact of then having a
00:32:43
base class and being able to do
00:32:45
inheritance and therefore the derivation of
00:32:47
the specialization via other classes
00:32:49
then we saw how this could
00:32:51
induce the possible creation or the
00:32:54
definition in any case of an
00:32:55
abstract class or even of an interface that
00:32:57
it is once again we know plus more
00:32:58
the same thing with a few details
00:33:00
pressure quibble and then to be able to set
00:33:04
up the mechanism
00:33:06
of polymorphism so the fact of having an
00:33:07
element which takes several times because
00:33:09
once again later we will no
00:33:11
longer manipulate the elements that of this
00:33:13
class or elements that of this
00:33:14
class at the risk of having to implement
00:33:16
other types if we add them later
00:33:18
but we will implement but in any case we
00:33:20
will manipulate this type directly and
00:33:23
then it's at execution of the program
00:33:25
which will have a dynamic resolution which
00:33:27
will be able to identify the real type
00:33:28
that we have at the very moment
00:33:31
it is processing and to call the
00:33:33
right functionalities therefore the right
00:33:35
methods accordingly and we will
00:33:37
no longer have to worry here about the manipulations of treatments to
00:33:39
check but who is
00:33:41
saying good night is it an
00:33:42
Englishman is it something else
00:33:43
is it someone else etc that is
00:33:46
really the whole principle of what I
00:33:48
wanted to explain to you here
00:33:51
I think we have covered quite a few
00:33:53
things I think everything is
00:33:55
said there so don't forget that if you
00:33:58
have at least generally a
00:34:00
virtual method of declaring the same having a
00:34:02
virtual destructure also is better
00:34:03
for it's more of a question
00:34:06
of habit by convention it's good to
00:34:08
proceed like this but I think we
00:34:10
've done the trick anyway we wo
00:34:11
n't be able to go much further for the
00:34:12
moment once again we are only
00:34:13
missing a few concepts that we have
00:34:15
not yet seen here we don't know anymore but
00:34:17
you already have a little bit of an idea
00:34:18
there so you see the advantage here
00:34:20
is that we won't even need to
00:34:22
modify this code in the end, we can
00:34:24
just add people who speak
00:34:25
our language to a group of people, a
00:34:28
grouping is not against us, we
00:34:29
work with
00:34:30
container structures and then we will just have to
00:34:32
do it once the call to this in
00:34:33
a loop for example by going through
00:34:35
a whole list a whole table and that's
00:34:38
it and we can add lots
00:34:39
of other different types of people
00:34:41
it will work very well so I hope
00:34:44
that was clear enough
00:34:46
once again there are surely things I could have already addressed this stage of the
00:34:49
course in this video but it doesn't
00:34:51
matter anyway it's elements
00:34:52
you see that work together a lot
00:34:53
so it's complicated to separate
00:34:55
the things by video as if we had to
00:34:57
see this thing before that other thing
00:34:59
when ultimately it is
00:35:00
still part of a whole and we could
00:35:01
see everything at the same time in reality so
00:35:04
we will progress gradually in
00:35:05
any case compared to to what we
00:35:07
have I think that for the rest
00:35:08
it will make the right transition
00:35:10
but we will move on to the container we
00:35:12
will start to approach a first
00:35:13
thing a priori we should approach the
00:35:15
tables there I can say it if it is
00:35:17
not it will go from anyway you will see it
00:35:18
very quickly in the next video but I
00:35:20
think that we will then approach the
00:35:22
tables to see a little what we
00:35:24
can do we no longer know
00:35:25
what functionalities are offered by
00:35:27
the standard library to handle
00:35:29
all that I say see you soon
00:35:30
don't hesitate to ask questions
00:35:31
really it's important in the
00:35:33
comments if you're stuck on
00:35:34
something there we're really attacking you see
00:35:36
object-oriented programming is a
00:35:38
paradigm that can be quite complicated
00:35:39
for some to learn especially if
00:35:41
you discover it with C++ if it is
00:35:43
your first programming language
00:35:44
with this paradigm it can be a little
00:35:46
confusing afterwards if you know all
00:35:48
these concepts in another programming language
00:35:50
again especially
00:35:52
a story of syntax you have to adapt to
00:35:53
the syntax of a new language but in
00:35:55
itself the concepts logically you
00:35:57
know them and if this is not the case it
00:35:58
gives you good revisions it
00:36:00
gives you some reminders and you will
00:36:01
only be better off there you go go out for the
00:36:03
rest see you soon and we will talk about the
00:36:06
paintings for the next session
00:36:07
plus ciao everyone
00:36:09
[Music]

Description:

Une interface, pour les gouverner tous ! Ou plutôt une exécution qui peut prendre plusieurs formes, selon le type réel des entités. 00:00 Introduction 00:21 Qu'est-ce que le polymorphisme ? 01:02 Code d'exemple 02:59 Mise en place d'un héritage 05:38 Méthode virtuelle dans une classe 07:24 Redéfinition d'une méthode dans une sous-classe 10:43 Ajout de nouveaux types pour le polymorphisme 12:28 Accès aux attributs depuis une sous-classe 15:24 Fonctionnement du polymorphisme 20:37 Point sur le polymorphisme ad hoc 21:16 Appel d'une méthode de la classe parente 22:34 Classe abstraite 25:04 Méthode virtuelle pure 26:55 Quelle différence avec une interface ? 32:30 Conclusion ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖ 💙 Si ce n'est pas encore fait, n'hésite pas à t'abonner à la chaîne ! ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖ ◾ Soutenir FormationVidéo : https://www.youtube.com/channel/UCS2e0hEJMhwd6bNscS60xTg/join ◾ Site web : https://jasonchampagne.fr/ ◾ Discord : https://jasonchampagne.fr/erreur ◾ Twitch : https://www.twitch.tv/jachampagne ◾ YouTube (personnel) : https://www.youtube.com/jasonchampagne ◾ Twitter : https://twitter.com/jachampagne8 ◾ Facebook : https://www.facebook.com/unsupportedbrowser ◾ Instagram : https://www.facebook.com/unsupportedbrowser ◾ Snapchat : https://www.snapchat.com/add/jachampagne8 🔵 Crédits : Musique proposée par La Musique Libre Wontolla - Can You Feel Me (ft. Nathan Brumley) : https://www.youtube.com/watch?v=quPybcMGosk Wontolla : https://soundcloud.com/iamwontolla Nathan Brumley : https://soundcloud.com/nathanbrumleysongwriter MERCI DE VOTRE FIDÉLITÉ 💙 !

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "C++ #20 - polymorphisme" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "C++ #20 - polymorphisme" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "C++ #20 - polymorphisme" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "C++ #20 - polymorphisme" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "C++ #20 - polymorphisme"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "C++ #20 - polymorphisme"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.