Classes Owning Their Objects

Can you explain the output from Program 8.5?

Program 8.5.

#import "Rectangle.h"#import "XYPoint.h"int main (int argc, char * argv[]){   @autoreleasepool {      Rectangle *myRect = [[Rectangle alloc] init];      XYPoint   *myPoint = [[XYPoint alloc] init];      [myPoint setX: 100 andY: 200];      [myRect setWidth: 5 andHeight: 8];      myRect.origin = myPoint;      NSLog (@"Origin at (%i, %i)", myRect.origin.x, myRect.origin.y);      [myPoint setX: 50 andY: 50];      NSLog (@"Origin at (%i, %i)", myRect.origin.x, myRect.origin.y);   }   return 0;}

Program 8.5. Output

Origin at (100, 200)Origin at (50, 50)

You changed myPoint from (100, 200) in the program to (50, 50), and apparently it also changed the rectangle’s ...

Get Programming in Objective-C, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.