• 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: why Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why Obj-C


  • Subject: Re: why Obj-C
  • From: Andy Lee <email@hidden>
  • Date: Fri, 5 Apr 2002 00:36:59 -0500

At 9:02 PM -0800 4/4/02, Dan Crevier wrote:
On 4/4/2002 8:46 PM, "Andy Lee" <email@hidden> wrote:

* "self" is really "self", by which I mean the method that gets
invoked for an object depends on the object's actual class at
runtime, unlike C++ where the method invoked depends on the
variable's declared type.

Maybe I'm just missing what you are saying here, but this is the basic
meaning of polymorphism, and is the way C++ works too. For example:

class A
{
public:
virtual void foo();
void bar() { this->foo(); }
};

class B
{
public:
virtual void foo();
};

void f()
{
B *b = new b;
A *bAsA = b;

bAsA->foo(); // calls B::foo()
bAsA->bar(); // calls B::foo()
}

You're right in this example, but as I recall, if bAsA->foo() is invoked in A's constructor, it will call A::foo(), on the grounds that it's not safe to use B::foo() before the object's B-ness has been initialized. (No jokes, please, about the object's "A-ness.") This is consistent with C++'s highly protective design and philosophy, but different from Java and Objective-C.

In Objective-C, [bAsA foo] would *always* call [B -foo] no matter where it's called. Likewise in Java, even in a constructor, and for that matter, in Smalltalk as well.

Sorry for speaking misleadingly. I should have remembered more specifically what I meant.

--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: why Obj-C
      • From: Michael Gersten <email@hidden>
    • Re: why Obj-C
      • From: Dan Crevier <email@hidden>
References: 
 >Re: why Obj-C (From: Dan Crevier <email@hidden>)

  • Prev by Date: Re: why Obj-C
  • Next by Date: Re: why Obj-C
  • Previous by thread: Re: why Obj-C
  • Next by thread: Re: why Obj-C
  • Index(es):
    • Date
    • Thread