• 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: Convenience Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convenience Methods


  • Subject: Re: Convenience Methods
  • From: Erik Buck <email@hidden>
  • Date: Wed, 26 Sep 2007 22:38:56 -0400

I take back my hasty and erroneous claim that there is no advantage to using immutable objects with the current version of Cocoa. It was just bone headed and stupid and ill-informed and I know better.

The "trick" is that when coding your own algorithms that depend on immutability, you absolutely must copy whatever immutable object you are using. If the object was truly immutable, the copy is very cheap and just retains and returns the same object again. If the object wasn't truly immutable, the copy may be expensive, but it's necessary and will produce the needed immutable object.

Given these facts of life:
If you are able to code an algorithm that works even if the relevant objects are mutable, you should probably do that. Attempting to code an algorithm that requires immutability may end up forcing you to make copies of objects. If performance is a concern, you must determine whether having to make copies is more or less efficient that just using an algorithm that doesn't rely on immutability.



This all comes down to the Liskov object oriented substitution principle: http://www.eventhelix.com/RealtimeMantra/Object_Oriented/ liskov_substitution_principle.htm


You must be able to use an NSMutableArray in any situation where an NSArray can be used because NSMutableArray is a subclass on NSArray. However, because of this, no algorithm can safely assume that the NSArray it was just given is really immutable.

_______________________________________________

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: Convenience Methods
      • From: Wade Tregaskis <email@hidden>
References: 
 >RE: Convenience Methods (From: Erik Buck <email@hidden>)
 >Re: Convenience Methods (From: Wade Tregaskis <email@hidden>)

  • Prev by Date: RE: Convenience Methods
  • Next by Date: RE: Convenience Methods
  • Previous by thread: Re: Convenience Methods
  • Next by thread: Re: Convenience Methods
  • Index(es):
    • Date
    • Thread