requiring methods in a subclass
requiring methods in a subclass
- Subject: requiring methods in a subclass
- From: Chuck Soper <email@hidden>
- Date: Mon, 8 Mar 2004 18:31:52 -0800
I have a class that requires subclasses. (Think of the typical Shape
super class with Rectangle, Circle, etc., subclasses example). I need
to require that each subclass implements certain methods. What is the
best way to do this with Objective-C? Is there a way to do it without
compiler warnings?
I also have some methods that are not strictly required. For those
methods, I allow the subclasses to override, if desired.
My approach is to define a protocol then declare my subclasses to
conform to it.
@protocol ShapeMessages
- (void)draw;
@end
@interface Shape {
}
@interface Circle : Shape <ShapeMessages> {
}
My Shape instance needs to call -draw, so, when I compile Shape.m I
get the following warning:
Shape.m:33: warning: `Shape' may not respond to `-draw'
Should I just ignore the warnings?
Is there a way to turn off the warnings?
Is this the correct way to require methods in a subclass?
Thanks,
Chuck
_______________________________________________
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.