Re: Dynamic Languages [was: Re: why Obj-C]
Re: Dynamic Languages [was: Re: why Obj-C]
- Subject: Re: Dynamic Languages [was: Re: why Obj-C]
- From: Chris Purcell <email@hidden>
- Date: Thu, 23 May 2002 13:42:04 +0100
Exercise 2: In the same library, there is a method for removing spaces
at
the beginning, but unfortunately this method has a bug. What do you do?
HINT: in Objective-C, you can override any method of any existing
class.
Not entirely true.
Categories can only override a base class method.
You cannot override a method in a category with a category.
PoseAs will allow you to _subclass_ these, but that's not the same as
override. This is the "Super's super" problem -- how do you skip a
buggy intermediate implementation and use the grandparent version?
Actually, I have a solution to many problems of this type - a method
that allows you to change the IMPlementation of a methods. Check out
http://www.cocoadev.com/index.pl?MethodSwizzling (this i a Wiki site, so
any page can be edited; use the History option at the top of the page if
it has been trashed)
In a nutshell: you add the alternative implementation to the class under
a different name, then swap the implementations. This bypasses the
Super's Super problem quite neatly, and *any* method is a class can be
changed this way.
Kritter out
_______________________________________________
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.