• 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
Re: OOP Clarification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OOP Clarification


  • Subject: Re: OOP Clarification
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 4 Jan 2002 15:36:33 -0800

On Friday, January 4, 2002, at 02:41 PM, Rick wrote:
>
> Same applies to Obj-C...you don't have "self" and "super"
> inside those class methods, so you can't override or access
> parent class methods. But, just as shown above, you can have
> the same class methods in multiple Obj-C classes.

No, self and super do exist in Obj-C class methods, and you can
indeed override inherited class methods.

@interface ParentClass : NSObject

+ myInit;
+ (void) mustImplementMe;

@end

@interface ChildClass : ParentClass

+ myInit;
+ (void) mustImplementMe;

@end

@implementation ParentClass

+ myInit
{
NSLog(@"initializing...");
return self;
}

+ (void) mustImplementMe
{
NSLog(@"This method must be implemented by subclasses! I quit!");
exit (0);
}

@end

@implementation ParentClass

+ myInit
{
[super myInit];
// do something else here..
NSLog(@"..and initializing some more");
return self;
}

+ (void) mustImplementMe
{
NSLog(@"We're still up, because I didn't call the inherited
+mustImplementMe method.");
}

@end


-jcr

"The problem with trying to child-proof the world, is that it
makes people neglect the far more important task of
world-proofing the child." -- Hugh Daniel


References: 
 >Re: OOP Clarification (From: Rick <email@hidden>)

  • Prev by Date: Re: OOP Clarification
  • Next by Date: Re: Newbie question on NSControl
  • Previous by thread: Re: OOP Clarification
  • Next by thread: Re: OOP Clarification
  • Index(es):
    • Date
    • Thread