Re: pure virtual methods?
Re: pure virtual methods?
- Subject: Re: pure virtual methods?
- From: <email@hidden>
- Date: Thu, 24 Jul 2003 20:27:43 -0000
Francisco Tolmasky <email@hidden> said:
>
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?
If we ever get a FAQ list going this should definitely go on it.
There is no way to make the compiler detect that one of your virtual methods
are not implemented as in C++. What I do in these cases is define all such
methods in the superclass and make the implementation of each method print a
message to the console warning that the method has not been implemented. So,
if a mistake is made, at least you can catch it at runtime.
If you are really paranoid about it you can put something in each
implementation in the superclass that will cause the program to crash or exit
to debugger. That way, you can make sure you don't miss the warning printed
to the console. If you do this, I recommend that you arrange things so that
this code is only compiled in the debug version of your app.
- Dennis D.
_______________________________________________
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.