Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.objective-c > #229

Re: A question on designated initializers

From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.objective-c
Subject Re: A question on designated initializers
Date 2015-11-25 01:49 +0100
Organization Informatimago
Message-ID <87oaeivr7a.fsf@kuiper.lan.informatimago.com> (permalink)
References <n2tcmc$t64$1@news.albasani.net> <n2u08d$7vs$1@dont-email.me> <n30iuo$c4b$1@news.albasani.net> <n32058$rkn$2@dont-email.me> <n32tc0$hik$1@news.albasani.net>

Show all headers | View raw


Jon Rossen <jonr17@comcast.net> writes:

> Ok....but backing up to the beginning of your paragraph:
> Hmmm, you lost me when you brought up your 'naked init' and said that
> it 'passes some reasonable defaults into the designated initializer'.
> The naked init in the current class just calls the current class'
> designated initializer and returns it.  How does it pass some
> reasonable defaults *into it*??  

"pass" as in "argument PASSing".  We're assuming the designated
initializer will take at least one argument, since otherwise there's
would be little reason for it to exist (it would just be a renaming of
the init method).  This passed argument is a default value specified by
-init.


> Might you be referring to the naked init that is the *superclass* of
> the current class?  Certainly the super's init does that when you do
> self = [super init].  I just don't understand how the init at the
> current level feeds anything into the designated initializer at that
> same level.

  -(id)init{return [self initWithWidth:1 andHeight:1];}

the defaults are 1 for the width, and 1 for the height.



> Speaking of nitpicks, in your code examples why don't you use
> (instancetype) as your return type?

I don't because I don't believe much in static typing.  I'm more a
dynamic typing guy, so I'm happy with using id.


Also, I'm not in a hurry, I can wait 300 ms more to get the right
results.


>> You'll notice how close to identical the code is for both cases - The
>> critical consideration is that you ALWAYS want your class' "init" to
>> chain back to the root object, whether directly or indirectly.
>
> Not only are they close, aren't they basically *the exact same code*
> structurally?  Meaning apart from the class-specific stuff that would
> be needed (different name of designated initializer, additional
> parameters, etc., etc.), the framework here is exactly the same as it
> was for the subclass (MyClass).  I would *expect* it to be the same
> seeing that it's keeping the init chaining intact.  Am I missing
> something or am I 'getting it'?

I don't agree with Don's code.  

In general the subclass should call:
   [super designatedInitializer:argument]
and not [super init], in its -designatedInitializer: method.

Notably, when the argument is given as a parameter to the subclass
-designatedInitializer:!


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

Back to comp.lang.objective-c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-22 13:39 -0800
  Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-22 14:48 -0800
    Re: A question on designated initializers Louis Wu <louiswu@ringworld.net> - 2015-11-22 16:26 -0800
      Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-22 17:24 -0800
        Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-23 02:39 +0100
  Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-23 01:18 +0100
    Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-22 16:49 -0800
      Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-23 02:02 +0100
        Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-27 17:19 -0800
          Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-28 13:22 +0100
            Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-28 17:37 -0800
              Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-29 03:45 +0100
  Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-11-22 19:15 -0800
    Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-23 18:44 -0800
      Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-24 04:58 +0100
        Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-24 16:42 -0800
          Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-25 02:00 +0100
        Re: A question on designated initializers Greg Parker <gparker@apple.com> - 2015-11-25 01:25 -0800
      Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-11-24 07:38 -0800
        Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-24 15:54 -0800
          Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-25 01:49 +0100
            Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-11-24 18:51 -0800
              Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-25 04:41 +0100
                Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-25 00:25 -0800
                Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-25 14:16 +0100
                Re: A question on designated initializers Jon Rossen <jonr17@comcast.net> - 2015-11-25 17:30 -0800
                Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-26 03:03 +0100
                Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-11-25 09:08 -0800
                Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-25 18:41 +0100
                Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-12-02 14:37 -0800
                Re: A question on designated initializers "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-12-03 00:58 +0100
          Re: A question on designated initializers Don Bruder <dakidd@sonic.net> - 2015-11-24 18:29 -0800

csiph-web