RE: OOP Clarification
RE: OOP Clarification
- Subject: RE: OOP Clarification
- From: Chris Hanson <email@hidden>
- Date: Fri, 4 Jan 2002 17:21:11 -0600
At 3:40 PM +0000 1/4/02, Smith, Bradley wrote:
When you say you can't overload static methods I'm not sure what you mean.
What he means is that you can't override static member functions in
C++ because they're not virtual.
In Objective-C, I can have the following:
#import <Foundation/NSString.h>
@interface A : NSObject
{
}
+ (NSString *)hello;
@end
@implementation A
+ (NSString *)hello
{
return @"Hello!";
}
@end
@interface B : NSObject
{
}
+ (NSString *)hello;
@end
@implementation B
+ (NSString *)hello
{
return [[super hello]
stringByAppendingString:@" How are you today?"];
}
@end
Sending hello to A -- [A hello] -- results in "Hello!" while sending
hello to B -- [B hello] -- results in "Hello! How are you today?"
This is because you can actually override class methods just like
instance methods, and because class methods also have access to self,
super, etc. just like instance methods do. (Self just refers to the
class object itself, not an instance, when used in a class method.)
-- Chris
--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden