1
00:00:02,640 --> 00:00:03,330
Hello everyone.

2
00:00:03,360 --> 00:00:06,690
So in this video we will learn about constrained functions.

3
00:00:06,690 --> 00:00:11,880
So before starting question functions let us first to review our code of function class that we did

4
00:00:11,880 --> 00:00:13,380
in the last session.

5
00:00:13,440 --> 00:00:19,710
OK so we have this function class this has two properties numerator and denominator and both the properties

6
00:00:19,710 --> 00:00:20,780
are private.

7
00:00:21,030 --> 00:00:27,210
Then we have a default constructor and then we have a better met base constructor which takes numerator

8
00:00:27,480 --> 00:00:28,930
and denominator as input.

9
00:00:29,390 --> 00:00:30,020
Okay.

10
00:00:30,120 --> 00:00:36,930
So we made these four functions these four functions were not present earlier but now we have made it.

11
00:00:36,960 --> 00:00:37,500
Why.

12
00:00:37,530 --> 00:00:41,950
Because the numerator and denominator property both add private field.

13
00:00:41,970 --> 00:00:46,430
So if we want to exist the numerator and denominator we have to make good friends central functions.

14
00:00:46,890 --> 00:00:50,480
So we have a function get numerator and only then numerator.

15
00:00:50,490 --> 00:00:55,260
Similarly we have a function get denominator so dysfunction returns through the denominator.

16
00:00:55,260 --> 00:00:56,990
Then we have a function set numerator.

17
00:00:57,000 --> 00:01:01,570
It will set the numerator said denominator it will set the denominator.

18
00:01:02,730 --> 00:01:03,280
Okay.

19
00:01:03,330 --> 00:01:10,920
And then we have brain function simplify function add function and multiply function.

20
00:01:10,980 --> 00:01:15,930
So all of these functions were killed in the last class we just created this for new functions.

21
00:01:15,990 --> 00:01:16,580
Okay.

22
00:01:16,680 --> 00:01:20,380
Get any set of functions.

23
00:01:20,460 --> 00:01:24,290
Now we have two objects faction EF 1 and faction EF 2.

24
00:01:24,360 --> 00:01:27,710
Okay so what is this index for creating AI and Deja constant.

25
00:01:27,950 --> 00:01:29,710
So this index is quite familiar.

26
00:01:29,760 --> 00:01:32,040
We are quite familiar with this index.

27
00:01:32,210 --> 00:01:35,190
So in days 5.

28
00:01:35,270 --> 00:01:44,080
Now if I want to create an digit constant and cause to be equal C so this is this index for creating

29
00:01:44,080 --> 00:01:45,230
and data constraint.

30
00:01:45,250 --> 00:01:51,730
Now similarly we can create object constraint we can create constant objects so this indexes fraction

31
00:01:54,320 --> 00:01:58,870
then constant keyword F3.

32
00:01:58,940 --> 00:01:59,290
Okay.

33
00:01:59,300 --> 00:02:02,060
So this is just an index for creating a unconstrained object.

34
00:02:02,060 --> 00:02:07,070
Now if I do B plus plus here this is wrong at everybody.

35
00:02:07,140 --> 00:02:09,660
Because we cannot change its properties.

36
00:02:09,660 --> 00:02:14,740
Similarly we cannot change the properties of f3 because it is a constant friction.

37
00:02:14,760 --> 00:02:17,550
We cannot change the properties of f3.

38
00:02:17,910 --> 00:02:18,540
Okay.

39
00:02:18,750 --> 00:02:19,920
So now let's encode

40
00:02:25,220 --> 00:02:33,140
so let us make a constant object so friction constant keyword F3.

41
00:02:33,210 --> 00:02:35,190
Okay now let us try to print the values.

42
00:02:35,190 --> 00:02:46,790
Let us try to printer's properties numerator and denominator so c out after dot get denominator Saudi

43
00:02:47,000 --> 00:02:50,120
we will first print numerator so numerator

44
00:02:54,420 --> 00:02:57,800
and now let us print denominator.

45
00:02:57,830 --> 00:03:02,020
So I have to don't get a denominator okay.

46
00:03:03,360 --> 00:03:12,850
Now let us try to change the value of numerator also so I have three not set numerator and let us give

47
00:03:12,850 --> 00:03:14,570
the value then.

48
00:03:14,650 --> 00:03:18,100
Okay so let's try to analyze what will be our output

49
00:03:21,010 --> 00:03:25,570
so we are creating a constraint object F3 since it is a constant object.

50
00:03:25,570 --> 00:03:27,620
We cannot change its properties.

51
00:03:27,790 --> 00:03:32,080
Okay but in the get numerator sort of this function is a good numerator.

52
00:03:32,320 --> 00:03:37,060
So in that get the numerator and get the number of function we are not changing the property.

53
00:03:37,060 --> 00:03:39,690
These function are just pretending the properties.

54
00:03:39,790 --> 00:03:40,290
Okay.

55
00:03:40,300 --> 00:03:46,990
So I believe we can call these functions but see this line set numerator so this function will change

56
00:03:46,990 --> 00:03:50,690
the value of numerator since this function change there enough numerator.

57
00:03:50,710 --> 00:03:55,990
We cannot call this function okay we cannot call a function which changes the properties of the object.

58
00:03:56,710 --> 00:04:03,650
So ideally these two will run fine and we will get error at this line we will get that at this thing.

59
00:04:03,650 --> 00:04:03,850
Okay.

60
00:04:03,860 --> 00:04:05,630
So what if I will come the.

61
00:04:05,690 --> 00:04:09,140
Then what will happen at this line.

62
00:04:09,140 --> 00:04:18,480
Default constructor will be called default constructor that we have created so our default constructor

63
00:04:18,480 --> 00:04:23,260
will be called and numerator and denominator property will be said to the god which values.

64
00:04:23,490 --> 00:04:30,630
And when we are printing the numerator the denominator we lose we will get garbage and garbage.

65
00:04:31,050 --> 00:04:31,310
Okay.

66
00:04:31,310 --> 00:04:33,930
Both numerator and denominator will contain language values.

67
00:04:34,500 --> 00:04:36,360
Okay so let us run our file.

68
00:04:36,750 --> 00:04:39,770
I believe we will get at the headline number two.

69
00:04:40,260 --> 00:04:41,460
So now let's see that it

70
00:04:44,590 --> 00:04:53,320
Okay so let's end this file so we are getting at it here because numerator user private property we

71
00:04:53,320 --> 00:04:57,080
have to call function get nominated.

72
00:04:57,130 --> 00:05:02,620
Okay so now let's send this file so I believe what should happen we should get that right line number

73
00:05:02,700 --> 00:05:05,000
one but we are getting an headline number 10.

74
00:05:05,000 --> 00:05:06,860
Now let us see data without that is

75
00:05:10,100 --> 00:05:11,360
so we are getting at it.

76
00:05:12,770 --> 00:05:17,120
Get numerator get dominated and certain numerator.

77
00:05:17,120 --> 00:05:24,150
Basically we are getting error on all the three functions we are getting error for this function get

78
00:05:24,150 --> 00:05:24,990
numerator.

79
00:05:24,990 --> 00:05:30,000
We are getting error for this get denominator and we are getting error for said numerator function.

80
00:05:30,060 --> 00:05:30,530
Okay.

81
00:05:30,630 --> 00:05:33,040
We have discussed we should get better at this line.

82
00:05:33,060 --> 00:05:35,530
But we are getting error at all the two functions.

83
00:05:35,610 --> 00:05:37,860
So that means there is something wrong with our approach.

84
00:05:37,860 --> 00:05:41,320
So our approach is wrong our way of thinking was wrong.

85
00:05:41,370 --> 00:05:42,750
There is something else.

86
00:05:42,780 --> 00:05:48,960
Okay let us try to understand what is wrong with our approach to actually what happens is when you create

87
00:05:49,200 --> 00:05:56,280
a constraint object so friction constant F3.

88
00:05:56,280 --> 00:06:02,430
So whenever you create a constraint object we cannot call any function through F3 we cannot call any

89
00:06:02,430 --> 00:06:08,550
function through F3 because compiler is worried about the function that you have called what is inside

90
00:06:08,550 --> 00:06:12,180
that function we some changes to our properties then it's a problem.

91
00:06:12,180 --> 00:06:12,680
Okay.

92
00:06:12,750 --> 00:06:17,670
So basically the compiler won't allow us to call any normal function through F3.

93
00:06:18,120 --> 00:06:23,460
Okay so compiler will not allow us to call any normal function to a constraint object.

94
00:06:23,460 --> 00:06:28,830
We can only call Constraint Function through constraint objects and not any normal functions.

95
00:06:28,860 --> 00:06:32,070
So now the question came What is a constraint function

96
00:06:37,100 --> 00:06:39,290
so what is the constraint function.

97
00:06:39,290 --> 00:06:43,790
A constraint function that does function that do not change the properties of the object.

98
00:06:43,790 --> 00:06:45,520
Okay so constrain functions

99
00:06:48,490 --> 00:06:50,320
which does not

100
00:06:53,860 --> 00:06:58,360
change which does not change any property

101
00:07:02,700 --> 00:07:03,770
of the current object

102
00:07:09,110 --> 00:07:13,700
Okay so constant functions are those functions which do not change the properties of the object.

103
00:07:14,480 --> 00:07:14,750
Okay.

104
00:07:14,780 --> 00:07:16,550
So I hope you have understood the problems.

105
00:07:16,550 --> 00:07:23,180
The problem is compiler will not allow us to call any normal function because the object is constant.

106
00:07:23,210 --> 00:07:27,200
Similarly we cannot call this function because compiler is worried about us.

107
00:07:27,260 --> 00:07:27,510
Okay.

108
00:07:27,530 --> 00:07:32,340
What if we inside the good denominator function which is the value of the denominator or numerator.

109
00:07:32,470 --> 00:07:36,230
I'll get a compiler won't allow us to call any normal function through a constraint object.

110
00:07:37,040 --> 00:07:39,710
Okay so we have to use constraint functions.

111
00:07:39,710 --> 00:07:42,410
Now let's see how to make a function Constraint Function

112
00:07:45,680 --> 00:07:48,680
so C we have a get numerator function.

113
00:07:48,710 --> 00:07:52,400
So what this get numeral function is doing it is simply returning the numerator.

114
00:07:52,400 --> 00:07:55,830
It is not changing the value of any of the properties of the object.

115
00:07:55,910 --> 00:07:59,120
So I believe we should mark this function as question function.

116
00:07:59,150 --> 00:08:01,740
So how do mark a function of constant function.

117
00:08:01,760 --> 00:08:04,740
We simply have to write a keyword constant.

118
00:08:04,790 --> 00:08:07,320
Now this function is a constraint function.

119
00:08:07,370 --> 00:08:07,870
Okay.

120
00:08:07,940 --> 00:08:10,940
And F3 can call this function similarly.

121
00:08:10,940 --> 00:08:12,400
Get denominator function.

122
00:08:12,440 --> 00:08:19,640
This function is only accessing their denominator property so we can also make this function as constant.

123
00:08:19,640 --> 00:08:24,930
Now the constraint object which is F3 can call this function okay.

124
00:08:25,140 --> 00:08:26,430
Now let's turn this file

125
00:08:31,740 --> 00:08:37,170
and now we will run this file now if we will run this file we will only get it for set numerator function

126
00:08:37,590 --> 00:08:42,030
and not error for getting the denominator end good no matter darn good denominator function.

127
00:08:42,090 --> 00:08:48,870
Okay okay so let's wrap this file so this time we are getting an error at line number 10.

128
00:08:48,910 --> 00:08:54,450
So if you will see that it so here that is only due to set numerator function.

129
00:08:54,600 --> 00:08:55,200
Okay.

130
00:08:55,290 --> 00:09:03,840
That is only due to set numerator function so this time we can call get numerator function and get the

131
00:09:03,840 --> 00:09:07,740
number to function because both the function has been marked as Constraint Function.

132
00:09:07,740 --> 00:09:10,180
So compiler will allow us to call these functions.

133
00:09:10,200 --> 00:09:10,670
Okay.

134
00:09:10,740 --> 00:09:14,630
So what compiler will do when we are calling this function get numerator.

135
00:09:14,670 --> 00:09:17,810
So compiler will go to get numerator function.

136
00:09:18,090 --> 00:09:19,300
So where is good numerator.

137
00:09:19,350 --> 00:09:24,000
So get new compiler will reach here get numerator function and this function is constant.

138
00:09:24,030 --> 00:09:26,380
So compiler will allow us to call this function.

139
00:09:26,460 --> 00:09:32,240
Similarly when you call this function get denominator so compiler will reach get the number to function.

140
00:09:32,340 --> 00:09:38,310
Since this function is a constraint function compiler will allow us to call this function and for set

141
00:09:38,310 --> 00:09:43,400
numerator function compiler will reach said no other function since this function is not constraint.

142
00:09:43,400 --> 00:09:48,230
Compiler won't allow us to call this function okay now.

143
00:09:48,280 --> 00:09:53,740
So tell me whether it said normal the function qualified to a constraint function or not.

144
00:09:53,770 --> 00:09:58,510
So the answer is set no matter the function cannot be a constraint function because it is changing the

145
00:09:58,510 --> 00:09:59,730
property.

146
00:09:59,800 --> 00:10:00,400
Okay.

147
00:10:00,490 --> 00:10:03,830
Now what if I make this function of Constraint Function.

148
00:10:03,880 --> 00:10:04,290
Okay.

149
00:10:04,370 --> 00:10:06,490
Eileen this should not be a constraint function.

150
00:10:06,490 --> 00:10:09,870
Now what if I make this function a constraint function what will happen.

151
00:10:09,880 --> 00:10:17,140
Now let us turn our file C we coordinated why we got an error because here we are trying to change the

152
00:10:17,140 --> 00:10:22,260
value of numerator and since the function is constant we cannot do this.

153
00:10:22,300 --> 00:10:22,780
Okay.

154
00:10:22,960 --> 00:10:24,470
So let's remove constraint here.

155
00:10:25,870 --> 00:10:27,010
Now let's send this file again.

156
00:10:27,940 --> 00:10:29,940
So this time our file is running.

157
00:10:29,950 --> 00:10:37,440
There is no added okay now said delimiter function can be a constant function or not.

158
00:10:37,690 --> 00:10:42,610
So same reason I said numerator side in order function doesn't qualify to be a constraint function because

159
00:10:42,610 --> 00:10:47,980
it is because it will try to change the value of denominator not print function at this dog world brain

160
00:10:47,980 --> 00:10:51,470
function can print function qualify for a question function.

161
00:10:51,490 --> 00:10:54,900
Yes it is because it is only accessing the properties.

162
00:10:54,910 --> 00:10:56,490
It is not changing the property.

163
00:10:56,560 --> 00:10:58,220
It is not trying to change that property.

164
00:10:58,240 --> 00:11:01,530
So brain function is a constraint function.

165
00:11:01,530 --> 00:11:05,100
Now let us talk about simplifying can it be a constraint function.

166
00:11:05,110 --> 00:11:06,150
The answer is No.

167
00:11:06,180 --> 00:11:06,430
Why.

168
00:11:06,430 --> 00:11:12,370
Because it is changing the value of because it is changing the properties so it cannot be a constraint

169
00:11:12,370 --> 00:11:14,380
function and function.

170
00:11:14,380 --> 00:11:20,230
It is also changing the properties numerator and denominator so it cannot qualify for a Constraint Function.

171
00:11:20,230 --> 00:11:21,290
Multiply function.

172
00:11:21,290 --> 00:11:26,090
It is also changing the numerator and denominator so it cannot be a constraint function.

173
00:11:26,140 --> 00:11:34,150
Okay so only brain function so only brain function and these two functions are qualifying for the constraint

174
00:11:34,150 --> 00:11:35,470
functions.

175
00:11:35,470 --> 00:11:36,210
Okay.

176
00:11:36,640 --> 00:11:41,200
So whenever we are working with the classes and objects whenever we are working with the functions we

177
00:11:41,200 --> 00:11:46,000
should look carefully it'll function can qualify for a constraint function then I believe we should

178
00:11:46,000 --> 00:11:51,610
make them a constraint function so that constraint object can call these functions.

179
00:11:51,610 --> 00:11:53,080
Okay thank you.
