Re: NSTimeZone and Abstract Classes
Re: NSTimeZone and Abstract Classes
- Subject: Re: NSTimeZone and Abstract Classes
- From: Simon Stapleton <email@hidden>
- Date: Wed, 31 Oct 2001 10:48:55 +0000 (GMT)
>
Subject: NSTimeZone and Abstract Classes
>
From: Joe Muscara <email@hidden>
>
To: email@hidden
>
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]).
There are a couple of TFMs in this case - ISTR the NSTimeZone
documentation is reasonably complete, and there should be a 'Class
Clusters' pdf in your documentation somewhere (at the root of
the 'Cocoa' subsection IIRC).
Of course, I could be waaaaay off course here, so feel free to flame
me at will ;-)
Simon
[1] At first glance, it might seem that 'name' is basic enough to
warrant a variable at the top level, but this would require the
public interface to have knowledge of the implementation of
the subclasses, and vice versa. This would be A Bad Thing.
--
PGP Key ID : 0x50D0698D
--
If the answer isn't obvious, the question is a distraction. Go find
an easier question.