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: email@hidden
- Date: Fri, 12 Aug 2016 11:38:10 +0900
> On Aug 12, 2016, at 11:20 AM, Steve Sisak <email@hidden> wrote:
>
> 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)
Politely disagreeing.
I think sub classing is implementation detail as well.
Class clusters are a bit more to learn, and hard to do well, but for this, it's really one right approach proven out by the frameworks and shouldn't be avoided.
They should be introduced so as to show the right path early. That may mean saying "I have some learning to do." But it's best to say that and understand at least early on there's not a shortcut to learning some things.
There is one other good approach here depending on class details, and it's a good one to also learn to use.
The design pattern of composition.
When the real mutable or immutable aspect of a class can be expressed and implemented by composing a simple class that has members that are existing mutable or immutable classes (usually collections like NSArray or NSDictionary)
then it's often the better choice. Less code less room for error and an interface that can work well with existing APIs. Also it can be a good opportunity to become familiar with the framework classes by wrapping calls to them in identical calls to the new composed class.
It can be a little boilerplate but removes a lot of decision making that might be unfortunate later.
Performance might later on suggest something more intense like a class cluster.
_______________________________________________
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