title: Objective-C getter/ setter
body: <p>I'm trying to work my way through an Objective-C tutorial. In the book there is this example:</p>
  
  <pre><code>@interface
  {
   int width;
   int height;
   XYPoint *origin;
  }
  @property int width, height;
  </code></pre>
  
  <p>I thought, "hey there's no getter/setter for the XYPoint object. The code does work though." Now i'm going maybe to answer my own question :).</p>
  
  <p>I thinks its because "origin" is a pointer already, and whats happening under the hood with "width" and "height", is that there is going te be created a pointer to them..</p>
  
  <p>Am i right, or am i talking BS :)  ??</p>
  
  <p>I just dont get it. here's main:</p>
  
  <pre><code>#import "Rectangle.h"
  #import "XYPoint.h"
  int main (int argc, char *argv[])
  {
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  
      Rectangle *myRect = [[Rectangle alloc] init];
      XYPoint *myPoint = [[XYPoint alloc] init];
  
      [myPoint setX: 100 andY: 200];
      [myRect setWidth: 5 andHeight: 8];
  
      myRect.origin = myPoint; 
  
      NSLog (@"Rectangle w = %i, h = %i",
             myRect.width, myRect.height); 
  
      NSLog (@"Origin at (%i, %i)",
             myRect.origin.x, myRect.origin.y);
  
      NSLog (@"Area = %i, Perimeter = %i",
             [myRect area], [myRect perimeter]);
  
      [myRect release];
      [myPoint release];
      [pool drain];
  
      return 0;
  }
  </code></pre>
  
  <p>And here's the Rectangle object:</p>
  
  <pre><code>#import "Rectangle.h"
  #import "XYPoint.h"
  
  @implementation Rectangle
  @synthesize width, height;
  
  -(void) setWidth: (int) w andHeight: (int) h
  {
      width = w;
      height = h;
  }
  
  - (void) setOrigin: (XYPoint *) pt
  {
      origin = pt;
  }
  -(int) area
  {
      return width * height;
  }
  -(int) perimeter
  {
      return (width + height) * 2;
  }
  -(XYPoint *) origin
  {
      return origin;
  }
  @end
  </code></pre>
  
  <p>What i dont understand is this line in main: <code>myRect.origin = myPoint;</code> I did not make a setter for it..</p>
  
  <p>BTW thanks for your fast reply's</p>