Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
June 22, 2018, 03:40:43 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: 8.4: XYPoint  (Read 1514 times)
Posts: 2

« on: February 24, 2012, 09:43:39 AM »

In chapter 8.4, we create a class called XYPoint to be used to store the coordinates for the Rectangle class.

I'm having trouble understanding the concept behind how this works, and more trouble understanding why you would want to do it like this. Why create a class, and put it inside another class to store information that you could inside the Rectangle class in the first place?

I'll understand if it was just done as an example, but I can't imagine ever wanting to do it like that when I could otherwise just create an x and y variable, and a method to set them...

Wouldn't this work just as well?
Code: (Objective-C)
-(void) setX: (int) xAxis andY: (int) yAxis
     x = xAxis;
     y = yAxis;

Any insight or help would be GREATLY appreciated! Thanks!

Posts: 49

« Reply #1 on: February 24, 2012, 04:50:12 PM »

As I understood from the book, it is done so you can use XYPoint class in the future. You might be working with other classes that need to set origin and having a separate class do that for you is, I guess, useful. As an example, you might be working with circles, triangles and/or any other objects that you need origin of, so instead of putting the same code everywhere (the same as yours), you just use XYPoint class.
Hope this helps.
Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 All rights reserved.