• 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: Garbage collector vs variable lifetime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Garbage collector vs variable lifetime
      • From: j o a r <email@hidden>
References: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Charles Srstka <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: public release of Xcode 3.1?
  • Next by Date: Re: Garbage collector vs variable lifetime
  • Previous by thread: Re: Garbage collector vs variable lifetime
  • Next by thread: Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread