End this demo let's unhandsome a student example. 2
And here is the Student class. 3
It is the same class we wrote earlier. 4
Only change I made as to public modify our new class declaration reliables constructor and update profile 5
method and that's for the sake of this demo site no expose's instance fields with public modifier veen 6
are that it is a bad design which leads to tight coupling so let's incorporate the sedation for effective 7
. 8
Item 14 it does make instances by weight and access them using getters and setters. 9
So let's go ahead and make this change. 10
So let's make all instance variables private 11
just copy this. 12
OK so now all the instance fields are by weight. 13
Let's also add again an answer for just the name field. 14
And it needs to be public. 15
That's. 16
I'd get her name 17
. 18
It's out of Sekar 19
it's initialized instance really. 20
So does not mean equals name. 21
So that's the setter on the getter and the instance variables are private. 22
Let's also change the constructor. 23
So here we have constrictors and the name is getting initialized in this overloaded constructor which 24
is it which is being invoked from here. 25
So let's just change this. 26
So let's just how only one single construct or sort let's make a gender here and let's just remove this 27
entire constructor and let's keep it simple 28
ones name. 29
So we now have a single constructor and we have the update profile Materne here. 30
And here is the student class from here. 31
If you recall we are actually creating the student objects from here. 32
We are creating three student objects initializing their state and printing their names. 33
And one of the names has been misspelled as Joanne serviette invoking the dead profiled method here 34
and passing the right name. 35
And then we are printing the right name after updating the profile. 36
And over here we are in the gender field. 37
And right now gender field is by red. 38
That's what we did. 39
So this should not compile. 40
Right. 41
And even here this constructor we have changed the constructor. 42
So we have to pass the right gender. 43
So let's let's just do that. 44
You just pass me here 45
or IGE is male and then what. 46
Anita it's female but gender is still a primate and we cannot access it. 47
So let's just compile and see. 48
So here it says gender has private access. 49
And student so we cannot access it directly so we can just remove this. 50
In fact we don't have to get a it not how to get her back and we don't need a sitter because we are 51
sitting here from the concert or Pettit's And so let's just go ahead and delete these three statements 52
and also instead of a big profile Let's actually said that mean said the correct name because we added 53
a setter and it's just said the correct name. 54
So let's just change this to set me. 55
And also here we cannot access it so it needs to be get mean. 56
So we are calling to get mean. 57
So we use only setters and getters no more direct access. 58
And hopefully this should compile fine. 59
Excellent. 60
And it's good on this. 61
That's it. 62
So we are printing the three students names and then we have the correct name because this was misspelled 63
and we are printing the right name here. 64
And that's about it. 65
So that's information hiding rule. 66
And it's also an off Joshua blocks favorite information hiding rule. 67
And that's at