title: Getter and Setter Explained?
body: <p>I am just learning OOP from a book I picked up (Big Nerd Ranch), and it just went through the getter and setter chapter. I would just like to clarify I understand what I have just done. Instead of creating a method to set the value of an instance, and then another method to extract the value and display it, I create use the <code>@property</code> and <code>@synthesize</code> syntax to define both methods. </p>
  
  <p>Instead of doing this:</p>
  
  <pre><code>-(void) setHeightOfObject:(int)h;
  -(void) setWeightOfObject:(float)w;
  -(int) heightOfObject;
  -(float) weightOfObject;
  </code></pre>
  
  <p>and defining it like this:</p>
  
  <pre><code>- (int)heightOfObject
  {
      return heightOfObject;
  }
  
  - (void)setHeightOfObject:(int)h
  {
      heightInMeters = h;
  }
  
  - (float)weightOfObject
  {
      return weightOfObject;
  }
  
  - (void)setWeightOfObject:(float)w
  {
      weightOfObject = w;
  }
  </code></pre>
  
  <p>I would do this with getter and setters in the .h file:</p>
  
  <pre><code>@property int heightOfObject;
  @property float weightOfObject;
  </code></pre>
  
  <p>And then go to my .m file and link it:</p>
  
  <pre><code>@synthesize heightInMeters, weightOfObject;
  </code></pre>
  
  <p>This then gives me the ability to set the value of my object, and then get it if I need it printed? I know this is an important concept and I want to make sure I have the proper grasp of it.</p>