Re: abstract class
Re: abstract class
- Subject: Re: abstract class
- From: "Shawn Erickson" <email@hidden>
- Date: Thu, 24 May 2007 09:00:09 -0700
On 5/24/07, Daniel Child <email@hidden> wrote:
Hi All,
I have seen Apple's documentation on "class clusters" as their way of
implementing the abstract factory pattern. What I don't understand is
precisely how (using Obj-C) you declare a class to be abstract and
set up the interface so that calls to the interface get routed to the
subclass.
I have just started studying this stuff and must be missing something
obvious, but even the gnu documentation mentions abstract classes
without giving an example. Could anyone show the briefest example of
how it works in Obj-C? Thanks in advance.
The Objective-C language has no language level support for specifying
a class abstract or methods for that matter. Of course you can
conceptually create abstract classes (one not mean to be directly
instantiated) that conceptually require subclasses to implement some
set of methods.
You can do this using various patterns... so the following is just one
example and likely the laziest of them. You can take further steps to
actually flag incorrect usage at runtime (attempts to instantiate the
base class, etc.) but often those are over kill IMHO.
// document that the following class is abstract
@ interface AbstractClass : NSObject {
...
}
- (void) someAbstractMethod;
... other methods ...
@end
@implementation AbstractClass
// document that the following method is abstract
- (void) someAbstractMethod {}
@end
@interface ConcreteClass : AbstractClass {
...
}
... other methods ...
@end
@implementation ConcreteClass
- (void) someAbstractMethod {
... implementation ...
}
@end
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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