Categories and adding instance variables
Categories and adding instance variables
- Subject: Categories and adding instance variables
- From: Kay Roepke <email@hidden>
- Date: Sun, 1 Aug 2004 19:27:27 +0200
Yes, I know it doesn't work. I know about subclassing.
Now that I said that ;-), here's my question:
Is there a technical reason that you cannot add instance variables to
class using categories?
Or is it just convenient for the runtime?
I have this generated class, lets call it Lexer. It inherits from
Scanner, which is part of an existing framework.
While generating Lexer's source code, I also end up with a enum
containing the tokens to be produced by Lexer.
Of course I could simply add this enum to the Lexer class and be done
with it, but guess what:
I have a Parser class which wants the very same enum, in order to know
which tokens it must
handle. Obviously, I don't want that enum to be duplicated in my
(albeit generated) code for
hygenical reasons.
In the C++ version this is done via multiple inheritance and in Java
one could simply make an
interface for this. ObjC on the other hand craps out.
Does anyone have a suggestion how this could be cleanly done?
One thing I came up with would be to use a static dictionary and get
the tokens from there, but that
seems like overkill to me.
Thanks,
Kay
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.