• 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: Are polymorphic objects possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are polymorphic objects possible?


  • Subject: Re: Are polymorphic objects possible?
  • From: John Hörnkvist <email@hidden>
  • Date: Sat, 2 Nov 2002 07:48:47 +0100

On Saturday, November 2, 2002, at 07:37 AM, Wade Tregaskis wrote:

Is it possible for an object to change at runtime what it appears to be, to the rest of the program? For instance, if I have two types of object, say WTFoo and WTBar, can I make another one under some name (WTMorphy, for example) which can pretend to be WTFoo & WTBar, as it likes? i.e. I get an instance of WTMorphy, tell it to be a WTFoo, then at some later point it changes itself to a WTBar?

I know this sounds strange, and I'm not pretending it's necessarily a good idea to ever actually do, but I'm curious if it's possible. I can think of a couple of instances where it might be worth testing this, depending on how well it can be done.

Just change the "isa" and you're done. The only real use I know of is "thunks" for lazy evaluation.

self->isa=[WTFoo class];

Regards,
John Hornkvist
_______________________________________________
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.

  • Prev by Date: Are polymorphic objects possible?
  • Next by Date: Re: Are polymorphic objects possible?
  • Previous by thread: Are polymorphic objects possible?
  • Next by thread: Re: Are polymorphic objects possible?
  • Index(es):
    • Date
    • Thread