Re: NSTimeZone and Abstract Classes
Re: NSTimeZone and Abstract Classes
- Subject: Re: NSTimeZone and Abstract Classes
- From: Chris Kane <email@hidden>
- Date: Wed, 31 Oct 2001 15:41:48 -0800
The primitive methods are usually declared in the class declaration
proper, and non-primitives in categories on the class, in the header.
For a class cluster that is (which NSTimeZone is). Plus you need to
override all the public init methods.
Implementing a subclass of NSTimeZone is a lot of work if you were going
to invent the data storage and whatnot yourself. It doesn't sound like
you want that, so this is probably a case where containment is the best
approach. You need a class that contains an NSTimeZone * which you
create (using NSTimeZone methods) at init time of instances of the new
class. If you want your class to look like an NSTimeZone in most
respects, then the new class can be a subclass of NSTimeZone, and you'd
implement the primitives to trivially call the same method on the
contained time zone object, getting it to do the hard work (and, the
primitives would NOT call super since super's methods are abstract).
Your init method overrides would not call custom NSTimeZone init methods
on "super" either (since they are also abstract), instead you should use
plain -init.
Chris Kane
Cocoa Frameworks, Apple
On Wednesday, October 31, 2001, at 01:51 PM, Joe Muscara wrote:
Thanks Simon. You're probably right. I think I have been in denial
because of the additional work I'll have to do assuming that NSTimeZone
is a class cluster.
So now the question (to you or anyone) becomes "how do I determine what
are the primitive methods that I must override in my subclass?" I
haven't found where these may be noted in any of the docs. I could find
them via trial and error, but I would hope there is a better way.
Joe
On Wednesday, October 31, 2001, at 04:48 AM, Simon Stapleton wrote:
I've defined ClockieTimeZone as a subclass of NSTimeZone. It's a
pretty minimal implementation, with the intent of adding one
variable and a method or two. Otherwise, I just want the
functionality of NSTimeZone (name, description,
isDaylightSavingsTime, etc.).
Unfortunately, every time I send a ClockieTimeZone instance a
message that includes a selector that's in NSTimeZone, I get an
error in the Console like the one below. I even get these when
initWithName is called. Can anyone tell me what I've obviously
overlooked?
"-name only defined for abstract class. Define -[ClockieTimeZone
name]!"
Well, my guess is that NSTimeZone is actually a class cluster, and
thus you have to implement all of the primitive selectors in your
subclass. Why? Well, the abstract (public) superclass of a cluster
has no (or, possibly, limited) instance variables due to the fact it
knows nothing about the implementation of its subclasses. It cannot,
therefore, provide any meaningful implementation of selectors that
would access such instance variables, hence the error you're seeing.
So, as the error would suggest, you need to define those 'primitive'
selectors in your subclass (-name, in this case[1]).
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev