Re: Garbage collector vs variable lifetime
Re: Garbage collector vs variable lifetime
- Subject: Re: Garbage collector vs variable lifetime
- From: Jim Puls <email@hidden>
- Date: Wed, 11 Jun 2008 00:29:04 -0700
On Jun 11, 2008, at 12:15 AM, Chris Hanson wrote:
This whole business about '(NSArray *) means NSArray AND any of
it's subclasses' is the result of sloppy thinking and confusing
'able to' with 'as per spec'.
No, you are wrong. It really is "per spec." That is an intentional
capability in both Objective-C and C++: You can return an instance
of a class, or any of its subclasses, wherever an instance of that
class is specified precisely because classes should be designed to
be substitutable in this fashion. This is the essence of
polymorphism in object-oriented programming and is summarized by the
Liskov substitution principle.
For that matter, it may be worth pointing out John's confusion between
"sloppy" and "incorrect". He makes a decent point that returning a
mutable object when the method definition specifies an immutable one
is sloppy and, indeed, fraught with peril.
But Chris is still correct that doing so is completely allowable, at
least under the true-in-Cocoa assumption that the mutable data types
are implemented as subclasses of the immutable ones.
-> jp
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden