• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
requiring methods in a subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Prev by Date: Re: [OT] Apple Developer Certification
  • Next by Date: Re: [OT] Apple Developer Certification
  • Previous by thread: Re: agvtools killing my plists
  • Next by thread: Encapsulate C struct/toll-free bridging?
  • Index(es):
    • Date
    • Thread