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

Re: isa


  • Subject: Re: isa
  • From: Marcel Weiher <email@hidden>
  • Date: Sat, 1 Jun 2002 10:15:52 +0200

On Friday, May 31, 2002, at 11:57 Uhr, Aram Greenman wrote:

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.

The problem was accessing overriden functionality of superclasses, and there is an easy way to get this without any tricks whatsoever, just good coding practices.

Instead of having a method

-doStuff // class A
{
lots of interesting stuff happens here
}

which you then override with in a subclass with:

-doStuff // class A' subclass of A
{
do my subclasses interesting stuff
}

and then not being able to access this in A''

-doStuff // class A'' subclass of A'
{
how do I get the original A implementation? -> you can't!
}

simply split this out into two methods

-doStuffA // class A
{
lots of interesting stuff happens here
}

-doStuff // class A
{
[self doStuffA];
}

now A' can override to its heart's content, A'' can still easily access the original A method

-doStuff // in class A''
{
[self doStuffA];
}

Done.


But, you ask, how do I do this when doStuff is defined in a system class that I don't have source code for?

Easy. You just have to do a bit of lateral thinking. Simply define a new selector, -doMyStuff and use that instead. For the system class you want to use, implement -doMyStuff { [self doStuff] } in a category.


I also suggested changing the object's isa temporarily, with the disclaimer that it might be a bad idea.

It is a very bad idea, especially the temporary swizzling.

So my question is, is that really a bad idea?

Yes. Of course, Objective-C is liberal, it won't stop you from trying out your bad ideas.

Assuming that none of the above dangers are present, can anyone see any problem with doing this?

Yes, unnecessary complication and confusion.

I would really like to get some opinions on this.

Enough opinion? :-)

Marcel


--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
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: Aram Greenman <email@hidden>
  • Prev by Date: declaring new apple script commands
  • Next by Date: Re: declaring new apple script commands
  • Previous by thread: Re: declaring new apple script commands
  • Next by thread: Re: isa
  • Index(es):
    • Date
    • Thread