Bindings: Where/when should dependent keys be registered? (when class with dependent keys is subclassed)
Bindings: Where/when should dependent keys be registered? (when class with dependent keys is subclassed)
- Subject: Bindings: Where/when should dependent keys be registered? (when class with dependent keys is subclassed)
- From: Jim Correia <email@hidden>
- Date: Wed, 27 Jul 2005 20:37:53 -0400
The example at:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CurrencyConverterBindings/03creatingmodel/chapter_3_section_1.html>
registers them in the +initialize method.
Is this recommended practice?
The reason that I ask is that
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
LanguageOverview/chapter_3_section_4.html#//apple_ref/doc/uid/
20001424-87244>
says:
The runtime system sends an initialize message to every class
object
before the class receives any other messages and after its
superclass
has received the initialize message. [...]
Because of inheritance, an initialize message sent to a class that
doesn’t implement the initialize method is forwarded to the
superclass,
even though the superclass has already received the initialize
message.
For example, assume class A implements the initialize method,
and class
[...]
To avoid performing initialization logic more than once [...]
But more importantly:
Note: Remember that the runtime system sends initialize to each
class
individually. Therefore, in a class’s implementation of the
initialize
method, you must not send the initialize message to its superclass.
This means if I have:
class Person
name (key)
uppercaseName (dependent key)
class Employee
department
and I do as the example suggests, that dependent keys won't be
registered for Employee if it implements +initialize, and per the
runtime docs, doesn't call send initialize to the super class.
What is the recommended/clean solution to this problem?
Thanks,
Jim _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden