Jul 18, 2008

(Objective-c) How to realize multiple inheritance

The Objective-c is single inheritance, but using Protocol allows to implements multiple class's methods, just like Interface in JAVA.

Here is an example :

@protocol MouseListener
-(BOOL) mousePressed;
-(BOOL) mouseClicked;
@end
@protocol KeyboardListener
-(BOOL) keyPressed;
@end
@interface Toto : NSObject
{
...
}
@end

So in the implementation of Toto we could override these listener's methods.

No comments: