isa
isa
- Subject: isa
- From: Aram Greenman <email@hidden>
- Date: Fri, 31 May 2002 14:57:25 -0700
A follow up to my own post:
Previously on this list we were discussing how to get an object to
behave like a class one or more steps up in the inheritance hierarchy. I
suggested two ways to accomplish this. +instanceMethodForSelector: is
one solution, the problem is if the returned IMP sends messages to self
those messages will still get sent normally and will invoke the
implementation of the object's true class, not the class we want to pose
as. This is the same behavior exhibited by messages to super.
I also suggested changing the object's isa temporarily, with the
disclaimer that it might be a bad idea.
So my question is, is that really a bad idea? Example:
- (void)foo {
Class wasa = [self class]; // remember true isa
isa = [Foo class]; // pretend to be a Foo
[self bar]; // calls -[Foo bar]
isa = wasa; // reset true isa
}
Obvious pitfalls include that the posing class may not respond to the
selector, or that the called method may send self a message the posing
class doesn't respond to, or that the called method or any methods it
calls in turn may attempt to access instance variables which don't exist
in the posing class. The first case can be checked for at runtime, the
latter two can't but could only occur if the object was posing only as a
class it didn't inherit from.
Assuming that none of the above dangers are present, can anyone see any
problem with doing this? I would really like to get some opinions on
this.
Aram
_______________________________________________
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: isa
- From: "John C. Randolph" <email@hidden>