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

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.

  • Prev by Date: Re: Flame retardant
  • Next by Date: Re: validateMenuItem: issues
  • Previous by thread: Re: Dynamic Languages [was: Re: why Obj-C]
  • Next by thread: Fielding another question
  • Index(es):
    • Date
    • Thread