Don't understand getter/setter methods


#1

I was reading the part where you create a new class Person, and make a simple BMI program. What I don’t understand is, what is the purpose of the getter / setter method. Why add it if the previous way is working ?
Could someone please clarify that for me. Thanks !


#2

What was the previous way? Try to be more specific.


#3

In Person.h that first approach is declaring these methods

[code]…

  • (void) setHeightInMeters:(float)h;
    -(void) setWeightInKilos:(int)w;[/code]

but using getter/setter it says to change it to

[code]-(float)heightInMeters;

  • (void) setHeightInMeters:(float)h;
    -(int)weightInKilos
    -(void) setWeightInKilos:(int)w;[/code]

Whats the purpose of the second approach