Re: NSDecimalNumber: Docs vs. Implementation
Re: NSDecimalNumber: Docs vs. Implementation
- Subject: Re: NSDecimalNumber: Docs vs. Implementation
- From: Michael Gersten <email@hidden>
- Date: Mon, 08 Apr 2002 21:01:41 -0700
I haven't checked with NSNumber,
+[NSString alloc] returns an instance of NSPlaceholderString, a hidden class.
All of the init... routines that actually do anything are located there.
>
NSDecimalNumber instances in Cocoa respond to -initWithInt:,
>
and return an object of class NSDecimalNumber.
So it looks like this init method is both in the number placeholder, and in the concrete subclass.
In a sense, this makes sense -- every other object (?) can be sent another init method to change the contents, so why not a hidden subclass of NSNumber?
Without seeing how things are actually done, I'd suspect (from this) that NSPlaceHolder<foo> is the subclass under NSFoo, and all the concrete subclasses are under placeholder. That way, all the init methods are shared, and any object can be re-init'd.
>
Now
>
-initWithInt: is an initializer for the parent class
>
NSNumber, which happens to be a class cluster. Therefore
>
NSDecimalNumber must be implementing its own version of
>
-initWithInt:, since (unlike inheritance from regular
>
("non-cluster") classes), init behaviors for parent cluster
>
classes are not inherited "unless explicitly documented."
>
(for some background and references, see the section on
>
background info at the bottom)
>
>
But the documentation for NSDecimalNumber does not
>
explicitly state anywhere that it overrides (or, perhaps
>
more accurately, "implements") the -initWithInt: method of
>
NSNumber.
>
>
Do I take it then that:
>
>
i) Within Foundation, concrete subclasses of class clusters
>
implicitly override all -init... methods, and hence this is
>
not explicitly documented
>
>
or
>
>
ii) I can only rely on those -init.. methods that are
>
explicitly documented for NSDecimalNumber; the others are
>
not supported
>
>
or
>
>
iii) The documentation for NSDecimalNumber is incomplete
>
>
or
>
>
iv) This is already discussed someplace, and I just haven't
>
found it.
>
>
Thanks!
>
- Rajiv.
>
>
-----------------------------
>
Some background:
>
>
Subclasses of class clusters must, in addition to overriding
>
primitive methods of the parent class, override any relevant
>
-init.. methods as well. The class cluster documentation
>
states that "[the subclass] should not rely on any of [the
>
-init... methods] that it inherits."
>
>
This was also pointed out by Ali Ozer in a post to
>
macosx-dev on Oct 31 2000, where he states further that
>
"unless otherwise explicitly documented, you usually do not
>
inherit the init behaviors from the root class." Indeed, if
>
I create a subclass MyNumber of NSNumber and do not override
>
-initWithInt: then the following line will raise an
>
exception in Cocoa:
>
>
MyNumber *m = [[MyNumber alloc] initWithInt:2];
>
>
*** Uncaught exception: <NSInvalidArgumentException> ***
>
initialization method -initWithInt: cannot be sent to an
>
abstract object of class MyNumber: Create a concrete
>
instance!
>
>
--------------------------------
>
>
-----------------------------------------------------
>
Protect yourself from spam, use http://sneakemail.com
>
_______________________________________________
>
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.
--
I am a Cocoa/WOF/EOF developer, and it looks like I'll be availble for hire. Please contact me at michael-job @ stb.nccom.com if interested.
_______________________________________________
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.