WEBVTT

00:00.540 --> 00:07.920
High in this session, we will discuss about encapsulation, so encapsulation allows us to restrict

00:08.280 --> 00:15.600
access to attributes and methods of a class by adding double underscored in front of the attribute or

00:15.870 --> 00:17.070
method definition.

00:17.580 --> 00:25.980
So whenever these methods and attributes become internal to class and can be accessed by the class itself

00:25.980 --> 00:29.400
and are not Colleyville outside the class, so let us see.

00:29.400 --> 00:38.940
I have certain methods or which actually modify the salary of the person, and I don't want any external

00:38.950 --> 00:45.900
method or anything else to actually be able to access the salary of a person because it is something

00:45.910 --> 00:48.020
which is related to the security of the person.

00:48.030 --> 00:49.560
It is the privacy of the person.

00:49.920 --> 00:57.240
So what I can do is I can make the salary and the methods which are excessive, the existing the salary

00:57.510 --> 00:58.470
as private.

00:58.890 --> 01:06.480
I can make them private by adding this double in the school in front of the variable or the attribute

01:06.480 --> 01:11.410
which is containing the salary or any variable which I want to make private.

01:11.760 --> 01:13.080
So that is all I can do it.

01:14.220 --> 01:20.490
So let's get further and implement encapsulation.

01:22.350 --> 01:26.280
So here I'll be implementing the same.

01:26.280 --> 01:32.690
So here I'm creating a class employee and I have a book inside this object.

01:32.700 --> 01:38.000
So this object is the old class which I am importing.

01:38.010 --> 01:43.900
So you would have understood by the pattern which is written here.

01:44.100 --> 01:46.500
So here how we write you.

01:46.650 --> 01:51.770
When we are creating a class inside the prisons, we usually provide the best class.

01:51.930 --> 01:58.430
So here we are using object as the base class for this particular class and we will start the definition.

01:58.440 --> 02:13.080
So we see death and we give the unit and we give the self inside this and then we will see says the

02:13.530 --> 02:17.430
name is equal to any name.

02:17.430 --> 02:18.540
See my name.

02:19.480 --> 02:22.360
Then we say says don't.

02:23.370 --> 02:26.340
Each is equal to any age.

02:27.390 --> 02:32.430
Then you say say not double under score.

02:32.430 --> 02:43.050
Salary is equal to the salary of the person, whatever the salary is right now what we do is we are

02:43.050 --> 02:44.560
creating an object of it.

02:44.580 --> 02:47.750
Now this is my class and I want to create an object of this class.

02:48.000 --> 02:52.410
So let's say I create an object, object one or we do one.

02:52.710 --> 02:57.140
And from this object, I want to create an instance of this.

02:57.420 --> 03:02.340
So let me get this and say employ

03:05.250 --> 03:09.540
and I can access the details of this.

03:11.100 --> 03:24.540
I can access from object one dot name for B.G., one dot age so I can print this right.

03:24.540 --> 03:30.990
And I can simply say print and I can print this here again.

03:30.990 --> 03:36.530
I can say print and I will be able to print this again.

03:38.490 --> 03:43.570
So let me love this so you can see I can I'm able to see the name on the image of the person.

03:44.070 --> 03:45.480
Now let me do one more thing.

03:45.480 --> 03:46.750
Let me I've decided.

03:48.510 --> 03:53.200
So now I'm doing the same thing and I'm putting silalahi here.

03:57.120 --> 04:03.220
Now, what happens here is it gives me this error, which is employee object has no attribute, double

04:03.310 --> 04:04.380
endoscopes gallery.

04:04.620 --> 04:09.170
So this is because it is treating it as internal in nature.

04:09.300 --> 04:18.130
It does not want to show it to other objects or any other function or any other method.

04:18.360 --> 04:22.140
So it is saying that it has nothing as a salaried set.

04:22.620 --> 04:24.250
So it is hiding it.

04:24.300 --> 04:26.280
This is called encapsulation.

04:26.280 --> 04:29.850
Encapsulation is basically data hiding.

04:30.300 --> 04:37.410
We are hiding this particular data from any other external sources and we are showing it only to the

04:37.410 --> 04:38.420
class itself.

04:38.430 --> 04:45.180
So any function which is present inside this particular class will be able to access this salary.

04:45.420 --> 04:50.670
But except from that, any other class or any other object will not be able to access this.

04:51.810 --> 04:53.210
So how we can do that?

04:53.220 --> 04:55.440
So let's do one thing.

04:55.440 --> 04:57.970
Let us see how we can modify that.

04:57.970 --> 04:59.890
So for that, let us feed on a.

05:00.120 --> 05:07.450
Examples will be class person and we put in objects again.

05:09.630 --> 05:15.650
Now we see death and now I'm creating see the.

05:25.370 --> 05:34.930
And each time a assigning name and age and I'm creating self and I'm giving names and I'm giving each

05:36.100 --> 05:49.710
next, I will go further and say self-taught name is equal to a name, age old age, self-taught.

05:54.140 --> 06:02.020
Now I'm getting the name and so I'm taking these now let me get this in a private one and let me create

06:02.030 --> 06:03.230
a private function.

06:03.420 --> 06:05.960
OK, so I create a private function.

06:06.440 --> 06:14.790
Let me move this one unclarity and I'm defining another function of this function is again, double

06:14.840 --> 06:18.620
underscored the split and it again, big self.

06:20.570 --> 06:23.390
And what it does is it simply prints

06:27.260 --> 06:32.150
itself, both name and self,

06:35.150 --> 06:37.130
not double under scrutiny.

06:37.170 --> 06:39.080
So this will display the name and age.

06:39.530 --> 06:42.100
And now let me run this from here.

06:42.110 --> 06:45.610
So I thought that will underscore the split.

06:46.040 --> 06:52.340
So I'm running this function from inside and after that I'm seeing it, Don.

06:55.070 --> 06:59.810
OK, now I don't run from this also.

07:02.130 --> 07:02.540
OK.

07:02.960 --> 07:06.380
And after that, I create an object so I can see for one.

07:07.120 --> 07:13.870
This is my first post and this is the person.

07:13.880 --> 07:16.430
So now it will create the person for me.

07:20.300 --> 07:27.050
Further, I see, for one thought, let me copy this so that this.

07:45.180 --> 07:53.400
So now what we have done is we have created the last person in that class person, we have created a

07:53.400 --> 08:03.970
fine name and age which takes name and age, and it assigns it to self and so forth, each leader.

08:04.020 --> 08:14.820
We have created a sense of this, which is actually and private method, which will again bring the

08:14.940 --> 08:16.740
name and age for this.

08:18.410 --> 08:20.030
Now, let us run this.

08:24.610 --> 08:29.430
So as we as this you can see there is no problem in running the design name and age.

08:30.040 --> 08:31.690
Next, we'll try to run the.

08:33.350 --> 08:36.950
This limited affects, so when you say for one.

08:38.730 --> 08:40.400
Not sign.

08:44.770 --> 08:48.130
So it's an anticipated.

08:54.360 --> 08:58.510
So when we're on this, we get an Ed Wood says personal object has more to go.

08:59.160 --> 09:02.160
Now, that is a common thing because it is a private matter.

09:02.670 --> 09:10.400
So now what we do is let us run the letters again, forget the name very clearly.

09:10.690 --> 09:15.450
And this one is, for one, the name.

09:17.140 --> 09:22.510
There's no problem in giving the industry the edge so to for one's

09:25.990 --> 09:26.490
age.

09:27.730 --> 09:30.790
So, again, the same thing, of course, an object has no of.

09:31.450 --> 09:34.810
So this is the property of glasses.

09:34.810 --> 09:43.570
When we use double store in front of any other method of defining it, then it will act as a private

09:43.570 --> 09:44.010
matter.

09:44.050 --> 09:51.790
That is, you cannot access it outside the method and it will be accessible.

09:54.810 --> 10:01.860
You can access it from any other method, so if I want to access it from this, from his name and age,

10:01.940 --> 10:04.190
I am able to access it.

10:04.440 --> 10:11.700
So whenever I've done this particular line, then it is being printed because it is right.

10:11.720 --> 10:18.300
We have just given the assignment to name and age and after that we have uncensored history.

10:18.630 --> 10:26.850
Now, if I don't give this, you can see and I will run this line so we won't give anything.

10:27.300 --> 10:36.540
So this means that it is running the cell door and is being drawn and also it is running from the Internet

10:37.020 --> 10:40.400
itself, but it is not even run it from outside.
