Re: pure virtual methods?
Re: pure virtual methods?
- Subject: Re: pure virtual methods?
- From: Fritz Anderson <email@hidden>
- Date: Thu, 24 Jul 2003 15:06:08 -0500
It's in the nature of Objective-C that the compiler doesn't do this
kind of enforcement -- or rather, the @protocol mechanism is the way
the compiler provides for enforcing required methods. You could have
both a root class "doing the dirty work," _and_ a protocol defining
your required methods.
Objective-C defers most class-taxonomy problems to run time. If you
really want your superclass to define a message, and tell senders
(through respondsToSelector:) that it responds to it, but have it yell
at implementors who don't override, you can provide an implementation
that contains just
[self doesNotRecognizeSelector: _cmd];
But there's no equivalent to the "pure virtual" function, reserving a
place in the vtable but not filling it; there is no vtable for you to
maintain. The usual way to not implement a method is simply not to
provide an implementation. Having all the subclasses of a class be the
first implementors of a method is OK.
-- F
On Thursday, 24 July 2003, at 1:28 PM, Francisco Tolmasky wrote:
Ok, in C++ if I made a method virtual =0, then subclasses would have
to define it. I want to do something similar in Objective C. I have
a class that inherits from NSObject but is to be used as a superclass.
It shouldn't be a protocol because it defines and does a lot of the
dirty work in the background, but all subclasses *should* define and
implement a number of methods. How can I ensure this happens without
making a separate protocol that people would have to make subclasses
adhere to?
_______________________________________________
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.