Understand Big Nerd Ranch's way


#1

Hi there,
at page 174 there are these lines:

I’m a newbie and I didn’t understand well.
Why with your style you override always the default designated initializer with a new one called init?

And what would be like with the “default” Apple’s way?

Thanks!


#2

[quote]
Why with your style you override always the default designated initializer with a new one called init?

And what would be like with the “default” Apple’s way?

Thanks![/quote]

As I’m understanding it, BNR is enforcing the idea that however it is that you’re going to be using your extended object, you’ll know what init parameters it will need. So by overriding the designating installer you’re enforcing whatever those init parameters should be. BNR is making the point that since those init parameters are going to be the same for every instance of the object, there is no reason to clutter up the calling object with a bunch of params. The calling object just needs to call [[Whatever alloc] init] and know that Whatever is going to take care of itself.

I don’t know so much that there’s an Apple way, it’s just that the API is written with inits that take params as needed, and Apple has no idea how you’re going to use these objects. But since you do know how you’re going to use the objects, you can use this technique to provide the init parameters as needed.

I think.


#3

Yup, that sums it up pretty good.