Amazon.com Widgets Chapter 10 - Section on "Initializing Objects" does not make sense.
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 23, 2014, 11:21:41 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
| |-+ Errata
| | |-+ 2nd Printing
| | | |-+ Chapter 10 - Section on "Initializing Objects" does not make sense.
Pages: [1] Go Down
Print
Author Topic: Chapter 10 - Section on "Initializing Objects" does not make sense. (Read 591 times)
stevemdavis
Newbie
*
Posts: 1






on: June 10, 2012, 02:57:52 PM

Hi there!

I have both the 3rd edition of this book and also the 4th (2nd printing). My fourth edition of the book is an electronic download from the Safari website.

I got to chapter 10 (in the 4th edition) and was reading the section on Initialising Objects. I found one part that I believe is incorrect and another where I didn't quite understand what was meant. So I would appreciate help on these matters.

"You've seen the pattern before: You allocate a new instance of an object (should that not be class???) and then initialize it, using a familiar sequence like this:

Fraction *myFract = [[Fraction alloc] init];

...a little later it goes on to say:

"To adhere to the rule stated earlier about a designated initializer, you should also modify init in your Fraction class. That's particularly important if your class might be subclassed. Here's what the init method could look like:

- (id) init
{
return [self initWith: 0 over: 0];
}

When your program begins execution, it sends the init method to all your classes. If you have a class and associated subclasses, the parent class gets the message first. This message is sent only once to each class, and it is guaranteed to be sent before any other messages are sent to the class. The purpose is for you to perform any class initialization at that point. For example, you might want to initialize some static variables associated with that class at that time."

So am I correct in thinking that the init method as shown above is called by the program when it begins execution? And if yes then why are we calling the initWith ( a = [[Fraction alloc] initWith: 1 over: 3]; ) method?

Many thanks,

Steve.



Last Edit: June 11, 2012, 11:28:09 AM by stevemdavis 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.