Welcome to this lecture.
This lecture is about the object oriented programming.
So by 10:00 supports multiple programming paradigm so we have already seen aboard the functional programming
that is defining the function to do tasks that is following the drive principle that is Don't Repeat
Yourself technique and we have learned about packing and unpacking the arguments through the functional
programming.
So now in this lecture we're going to learn about the objects.
So we'll simply bar from the same principle programming but with the creation of the object that is
making the instances and creating the class in object and seeing the most basic advantage and basically
the paradigm of the object oriented programming.
So let's get it started.
So before that let me tell you about objects.
So what is basically object let me open my document over here.
So you could see we have the object over here board.
So this is objects so this thing Bard is an object and we have the attribute and methods to this object.
So first of all this object has its attribute it has its own properties so you can see this board can
have the name.
So this part can habits is.
So these are the properties of the attribute to this board.
So if you make another object they can have the different name or the different ID.
So this is basically unique.
So attributes will be unique to each of these objects so this is board are basically if you make something
like let me say penguin.
So if you make the penguin object it will have different name.
It will have different aides and if you make something let me say Barrow dirty Sparrow stain it will
have different name and different days.
You can say same case for the sparrow.
So each of these objects will have a unique name and the A's but their method will be common.
They can sing they can dance so Bard object having that let me say we'll make the classes a board in
dyslexia and we'll see how this object oriented programming works under the hood.
So first of all let me just open my script over here and I have the same.
This is script.
So first of all in order to create the class you have to call with this keyword saying class.
So all in the lowercase.
And now let me say board is my class.
So let's give the column to represent that we are creating this board class.
So now we are inside this class.
So first of all in the class will have the attributes.
So you can simply say something like spaces.
So that will be bored.
So this is your barometer survey what we call the attributes.
So you can see these are the attribute to this board.
So we species will be bored in the next one is your method method to the class.
So let me just define one real quick funny one over here.
So if you just remember we have to define the method in the class that is with this def keyword.
So if you just remember in the previous couple of lecture we have defined the function with this same
def cured.
So that means this is also a fun sin but this is bound to particular class.
So if any fun sin is bound to any particular class we normally call it it's a method but the same is
fun and it will define it with a def cured.
Now let's do something like double underscore in it and double underscore.
So this is the first main method of any class.
So this remember that this is the first method which is init method and we normally call it is a constructor
in other programming languages like Java.
So if we just see here way here what we're doing is we're just making a constructor.
And let me just type here real quick and so you what is going over here
so if you just remember in the document over here I say that this is the object it will have its own
attribute name and dates.
So we are just defining a constructor that is the first method to this class board with this in it method
and this method has this self.
So this self is bound to particular object to this.
Remember the first argument to any method of the class is going to be self.
If we make any other method let me say the new method and that will be seeing then the any method the
first arguments should be self.
So just remember that if we just remove this self it is not going to work.
So you have to put every time the self is a first parameter in the method of the classes.
So if you see here after the sale we have the name and the AIDS.
So these are the attribute to the particular object.
So let me say self this and the next one would be song.
OK.
Will this pass is a song which is going to be sing by the bird and we'll just say return by formatting
something and Alyssa sings endless format with format keyword.
We know how to format.
That is by the format once.
And now if we'd say something like name and the song that to just.
This is not going to work.
So let me show you why this is not going to work.
So before that I have to make the object.
So first of all this remembering the object oriented programming first part is creating a class that
we just create here with the class skewered and giving the name of the class and just remember that
the naming convention over here class name always starts with uppercase.
That is b over here is capital.
If you make any other class like bike then B will be capital over here.
So this is about class.
So the first letter of the class will be in an upper case and after that the first method of any class
is a unique method which is the constructor and this method is going to be called when you instantiate
the classes object so if you make the instances of the class then this method is going to be called
automatically.
So let me show you how to do this.
Make instances of the classes.
So in order to make the instances you have to give the name to that object.
So first of all let me say the Bard will be penguin.
So Penguin is my bird.
So this is the name.
So this is the name of the object.
So after that you have to type the class's name.
So that is barred.
OK.
We are just making a class name here.
So this is a bird and give the parents is.
So I told you before that to make the object of the class the first method that is going to be invoked
is this constructor.
So when you just pass this as a board when you just create this penguin is the object of this bird class.
This method is going to be called automatically and if you see here we have different argument to this
one some other method.
So first is self so self is particularly this denoting that this is the current objects ourselves to
not be assigned by this name and is to be assigned.
So let's give the name in the is to this bird.
So the penguin bird will be he okay and thus giving the name randomly and that is is.
Let me say 4.
So if you do this then you have created the penguin object of this bird class and this method is going
to be invoked.
And if you see herself.
So if you see this selfie is pointing to this particular object that means you need not have to explicitly
assign this self of value over here.
You need not have to be passed but except self.
All of these arguments should have the Buddhist null argument right here.
So we are just giving heed to this name we're giving for.
This is now if you see here.
This self is pointing to this particular Penguin.
That means we're making this name and is of this bar class pointing to this penguin in words denoting
that this name should be he.
And this is before.
That means we are assigning this he and four to the object class attribute.
So if I talk here about this attribute to other properties of the object that is name and it is that
means we are just saying something like Okay assign this board name naming is is the class attribute.
So we are just doing that.
So let me just roll it back again.
And now if you just see here we are creating this penguin class.
So that means we have no name and we have now is but this go over here and we have to now call the Singh
method.
Let me just call listing methods to Singh method is not the init method or the constructor.
So in order to call any other method that is beyond that a normal method or basically constructor that
is going to be called we adopted.
So first of all just give the object name which we just created over here.
That is Penguin dot Singh's or Dart is to be given a period and this method is to be called.
So if I say Penguin dot sing and now we have to pass song because I have a little self is not to be
assigned by anything but the song has to be assigned.
So if I say hello.
Is the song that the penguin is singing.
So if I just call this then let's see if this is going to work or not.
So obviously this is not going to organize also we way.
So it is saying that name is not defined.
So let's go and see why it is not defined.
So the interpreter is not swinging either while creating the object.
That means we have successfully created the penguin object.
But while defining or when calling this Singh method over here from this object we are getting either.
So Hilo has been passed in the sun.
If we see here this song is not the attribute of the class.
If it has to be attribute of the class it should be a sign over here and an should be given with the
name of self doubt.
Song to be the song because we have to assign it with the cell because we are just denoting to this
class attribute.
But it is not the song which is the attribute that means you don't need to just do something like self
song because it is not your class attribute.
But if you see this name names classic attribute which is this attribute we are not passing anything
from here so that means it should have self doubt Nim which is just denoting does this penguin object
in this song.
So if I say this again and is present fine and okay.
It is not doing anything because we are just returning but we are not printing.
Let's go over here and print this list of this special five.
It is saying he sings Hello.
He was the board name obviously.
Let's give something name here.
Green is board name and it is saying hello hello is singing so let's save this in previous year five
then it is saying Green sings Hello hello that means we have now successfully call this sing method
of this bar class from this object with this penguin observer so you can see we're making the instances
here.
So this is instance which is obviously the object Penguin and it is called from this bird class any
food just make the instances duck class or basically the method that is going to be invoked automatically
is this in its matter which is obviously a constructor and this self is just denoting to this object
that means we don't need to pass anything to the self.
And after that this is all put in an argument which should be passed to while calling these ball class
and that is with the green is the name for is that is if you want to reference that is you can just
go here and list these things and he's it is is you can format now but now we are just passing self
good name it disposition song is positive disposition and it's sort of passive this placeholder but
now again if you say something like Well it is let's say this and place if I didn't it is not going
to run again because it is is not defined because is is the class attribute.
So if you want to assist the class attribute it solely from the self so if you just remember or if you're
from any other programming language like Zella it should be something like this in the case of Java.
So this is in the case of that about where this pointing the particular object and in the case of Python
it is done with self keyword let's say this and press five and it also has green things hello hello
and his is is 4.
So we have successfully created the bar class over here Penguin and we have seen how to this define
a method so next thing is we have seen here that matters is sing and the dance so let's create this
dance method also so you know how to create the method now.
So it is dawn inside the class and with a dance and now the first argument to this method will be self
and we don't want anything to be bus only self that means will this make the fence and over here.
Will return something from this function and that is just is now dancing so let's format this and this
should be formatted with let me say a name so if you again do only name then this is not going to work
because this name is your class object so it should be just referenced with this self cured because
it is the class attribute just remember that and now if it's this go down here and in order to call
this a done subject you have to call from your penguin so before that let me print again and you should
be Penguin which is your object and in order to invoke any method of the class you have to do so give
it a period and the dance is the method you want in book end if you just pass here nothing that means
if you see I only told that self need not to be assigned and after school there is nothing that means
you simply call this dance if I say this now and press apply we will see green is now dancing that means
we have just created the penguin here class and now you can also create any other object to let me see
parrot is my next object so it is also a board it is also created from the bird class and now blue is
the parrot which is obviously not true green will be the better but let me say it is blue in five days
and you can now scald this case would be printed first and let me again now call these sink method let's
see how this works.
So if you see in this sing you have to call with the song.
So we have to pass the song again
here is the song.
Let's save this again.
Press five we will see now Bloom sings Hey hey.
In his is is five which is a spicier here which is basically the battered object and we're just calling
this which will be assigned to this is a name and now pattern it's also singing so you can see we can
make the instances of the class multiple times or many times you can also make an order bar now if you
make a sparrow and okay a sparrow and it is also created from the bird glass and it will have a different
name let me say.
Or is the name and it will be 45 days and let us print this again with a sparrow now and it is also
singing something high singing Let's close this save this place of I will see all the things on his
is is forty five.
So one thing you can see over here is every object will have different attributes which is name and
its so you can see Penguin has different name different days parrot has different name different days
The Sparrow has different name different dates so each of these object will be different in terms of
its properties are the attributes but if we see here the method seeing in a dance is common for all
of these instances so that is common for Penguin that is common for a pattern because whereas this calling
the sing and dance for each of this so that is the important thing of the object oriented paradigm will
make our object to perform different tasks that is from these bar class or basically will make a class
which will be a prototype from which object can do something.
So this will be common for many objects but just remember it's of these objects is independent of each
other they can work independent of each other this penguin can do something else then the battered but
they will be inherited or they will be derived from this prototype is a class so in the next lesson
will learn about the inheritance.
The most important programming paradigm of the object oriented so let's see in the next step towards
is going to be really interesting zebra.
So this will be there for this lecture.
See you in the next one.