• 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: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)


  • Subject: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • From: email@hidden
  • Date: Fri, 12 Aug 2016 10:04:18 +0900



> On Aug 12, 2016, at 9:16 AM, Steve Sisak <email@hidden> wrote:
>
> There’s a standard idiom where immutable classes frequently have mutable subclasses (which expose the mutating methods).
>
> In this case, it’s common for the immutable (super)class to adopt NSCopying and the mutable subclass to also adopt NSMutableCopying.
>
> This way if you want to add an object to a collection, calling -copy has the effect of freezing the current value ― the immutable class can optimize this by just returning a new reference to the same object, but the caller doesn’t have to know whether the object was immutable or a mutable subclass.

Almost.

The design pattern for this is the class cluster.
Where the public interfaces may produce private subclasses that handle and respond appropriately to the messages that make them one or the other.




_______________________________________________

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: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
      • From: Steve Sisak <email@hidden>
References: 
 >Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Sasikumar JP <email@hidden>)
 >Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol) (From: Steve Sisak <email@hidden>)

  • Prev by Date: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Next by Date: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Previous by thread: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Next by thread: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
  • Index(es):
    • Date
    • Thread