Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
- Subject: Re: Objective-C basics - (Why NSNumber conforms to NSCopying protocol)
- From: Steve Sisak <email@hidden>
- Date: Thu, 11 Aug 2016 22:20:32 -0400
"On Aug 11, 2016, at 9:04 PM, email@hidden wrote:
>> 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.
Actually, to be pedantic, class cluster is an implementation detail — was trying to impedance match to OP’s experience level.
Was speaking purely in terms of public interfaces (since he’s a consumer rather than implementor).
-Steve
_______________________________________________
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