Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
- Subject: Re: What is the equivalent of a C++ pure-virtual function in Objective-C?
- From: Alex Curylo <email@hidden>
- Date: Sun, 11 Jan 2009 18:46:20 -0800
On 11-Jan-09, at 6:32 PM, email@hidden wrote:
Still,
anyone wants to give me some guidance on protocols and how they should
be employed, I'm all ears (eyes).
Well, here's one I just employed. Define it like this
@protocol PAImageCollection <NSObject>
@required
- (int)collectionCount;
- (UINavigationController *)collectionController;
- (NSString *)fileForIndex:(int)collectionIndex;
- (BOOL)canRemove;
@end
and then any class you declare like this
@interface FavoritesTableViewCell : UITableViewCell <PAImageCollection>
will throw up a compile error if it doesn't match everything under
@required in the protocol.
And to keep track of a derived instance as a variable/argument,
something like
id<PAImageCollection> collection;
does the trick.
That should pretty much cover any sane use of pure virtual functions
you have in mind.
--
Alex Curylo -- email@hidden -- http://www.alexcurylo.com/
"I misjudged you Alex; you're a @#$%!!, but you're a consistent,
smart $#@%^!!, and the kind of @$^#&$!! I can #$@*&!! respect."
-- John G. Spragge
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden