• 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: Greg Titus <email@hidden>
  • Date: Fri, 4 Jan 2002 15:19:22 -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.

Um... no. You do have self and super in class methods, and you can easily override and access parent class methods because classes are first-class ("real") objects. They are normal methods in every respect except that "self" is a Class object.

@interface A
+ foo;
@end

@interface B:A
+foo;
-bar;
@end

@implementation B

+ foo
{
[super foo]; // calls A's +foo
[self name]; // returns "B" -- self is a Class object
[[self alloc] init]; // is the same as [[B alloc] init]
}

- bar
{
[[self class] foo]; // calls B's foo. The method is overridden...
}

@end

Hope this helps,
--Greg


  • Follow-Ups:
    • Re: OOP Clarification
      • From: Rick <email@hidden>
References: 
 >Re: OOP Clarification (From: Rick <email@hidden>)

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