Amazon.com Widgets 8.4: XYPoint
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 17, 2014, 08:27:16 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ Chapter 8
| | |-+ 8.4: XYPoint
Pages: [1] Go Down
Print
Author Topic: 8.4: XYPoint (Read 707 times)
Jessew6889
Newbie
*
Posts: 2


Email




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!

-Jesse
Logged
MCaEd
Newbie
*
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.
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

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 (c) 2009 classroomM.com. All rights reserved.