• 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: Marco Scheurer <email@hidden>
  • Date: Fri, 4 Jan 2002 17:25:39 +0100

On Friday, January 4, 2002, at 04:40 pm, Smith, Bradley wrote:

Well, it does have a 'this' in the sense that it can access other static
variables and methods.

In Foundation's NSObject:

+ (id) alloc
{
return [self allocWithZone:nil];
}


+ (id) allocWithZone:(NSZone *) aZone
{
// ...;
}

If you override +allocWithZone in the Foo subclass of NSObject, [Foo alloc] will use Foo's allocWithZone implementation. Does it work like so in C++? I maybe mistaken (my C++ is rusty... ), but I think not.

When you say you can't overload static methods I'm not sure what you mean.

I meant overriding. Can you redefine a static method in a subclass and invoke the base class implementation?

@implementation Animal
+ (void) doSomething
{
//...
}
@end

@implementation Tiger : Animal
+ (void) doSomething
{
//...
[super doSomething];
}
@end


I'm not trying to get into an argument here, it's just that I'm new to Obj-C
and in my head I had class members in Obj-C as analagous to static members
in C++. Would someone care to point out the differences, and I mean the
differences in how one can be used in a way that the other cannot.

For sure they can be used in analogous roles. Just as static variables are sometimes used as a poor man's replacement for the lack of class variables in Objective C, but there not exactly the same.

Other things that you cannot do with them are, of course, the runtime things that you can do with all methods in Objective C (including class methods) that you cannot do with any function.

marco

Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch


  • Follow-Ups:
    • Re: OOP Clarification
      • From: Rick <email@hidden>
    • Re: OOP Clarification
      • From: Andreas Monitzer <email@hidden>
References: 
 >RE: OOP Clarification (From: "Smith, Bradley" <email@hidden>)

  • Prev by Date: Re: Can these be done in Cocoa?
  • Next by Date: Re: Running a regular expression on an NSString
  • Previous by thread: RE: OOP Clarification
  • Next by thread: Re: OOP Clarification
  • Index(es):
    • Date
    • Thread