categories vs sub classing--a tradeoff question
categories vs sub classing--a tradeoff question
- Subject: categories vs sub classing--a tradeoff question
- From: Mark Dawson <email@hidden>
- Date: Mon, 17 Jan 2005 17:32:32 -0800
I want to replace calls to
NSTextField field's setFloatValue, with a call through to my formatter. I'm not sure which is the best way to do this--a category or a sub class. As I'm learning ObjC, I wanted to understand the tradeoffs.
I want to do a [fieldWidth setFieldSize:floatVal] where "setFieldSize" would translate floatVal & call fieldWidth's formatter to correctly display it.
The advantage of using a subclass, I assume, is that I can cache the formatter(i.e., fieldWidthFormatter = [self formatter]). A category, though, will allow me to extend NSTextField to know about my formatter without having to modify every text field in IB to use a new subclass (I would, I think, for both cases need to check that the text field actually has a formatter of the right type). So it seems time-wise, a category would be the way to go. Would the caching be worth worrying about? Are there any other tradeoffs to consider? Thanks!
Mark _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden