Re: Subject: Re: Category vs Subclass
Re: Subject: Re: Category vs Subclass
- Subject: Re: Subject: Re: Category vs Subclass
- From: Ondra Cada <email@hidden>
- Date: Fri, 17 Aug 2001 10:43:53 +0200
James,
>
>>>>> James Brasure (JB) wrote at Thu, 16 Aug 2001 16:37:10 -0600:
JB> All this talk about categories vs. subclassing got me thinking. What is
JB> the advantage of using categories rather than subclassing? (I'm kind of
JB> new to Cocoa).
Well, using a category you get, I guess, three main advantages:
- the code is usually much simpler (more easy to write, debug, maintain, and
upgrade);
- it supports new services for *already* existing objects, like
@interface NSString (MyGreatExtensions)
-mySuperbNSStringAddition;
@end
... normal code ...
NSWindow *someWindow...
[[someWindow title] mySuperbNSStringAddition]
With a subclass, you would need to convert the string (unless you poseAsClass: it).
- it works without extra care for class clusters.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc