• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: semantics of init -> Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: semantics of init -> Question


  • Subject: Re: semantics of init -> Question
  • From: Marcel Weiher <email@hidden>
  • Date: Thu, 5 Jun 2003 22:42:14 +0200

On Thursday, June 5, 2003, at 03:27 Uhr, Oscar Morales Vivs wrote:

Another situation would be when the setting of a variable is connected with
some other action, as for example a notification being sent. Of course, one
can in that case write a public and a private setter with the private setter
setting the variable and the public setter calling the private setter and
posting the notification (This is more a design problem)

This is what I was thinking. However I'm in doubt about something. Let's see...:

Suppose I have class A, and class B derived from it. If I create a new object of class B, and during the execution of class A 'init' I call a method that is overriden in class B, will it call class A version or class B version?

Init is not special in any way, and that is as it should be.

It that's the case, then I wouldn't suggest using accessors in init as you can't know what derived classes could do with them.

Au contraire: this is a reason *for* using accessors. After all, the derived class might require some special action when a certain instance variable is set, which you will be short-circuiting by accessing the instance variable directly -- just like any other direct instance variable access! Furthermore, there is no easy way for the subclass to get around this, because it probably has to call the super init.

On the other hand, it is easy for the subclass to (re-)define any accessors used to get the desired effect.

Essentially, you cannot know what subclasses will do with your class's invariants, and you cannot be responsible for subclasse that break them.

Could cause problems if the derived class accessor needs some data that hasn't been initialized. It's a bigger problem in C++, but it can also be a problem in Objective-C.

I would suggest it is a bigger problem in C++ because there the whole "initialization is special and 'protected'"-nonsense is a language feature...

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
f0249ab8b1af193ef5addcf39fdff5ca
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: semantics of init -> Question (From: Oscar Morales Vivó <email@hidden>)

  • Prev by Date: Re: Trimming text in a tableview
  • Next by Date: Re: TextView problem
  • Previous by thread: Re: semantics of init -> Question
  • Next by thread: Re: semantics of init
  • Index(es):
    • Date
    • Thread