On Apr 18, 2008, at 5:54 PM, Jack Repenning <[EMAIL PROTECTED]> wrote:

On Apr 18, 2008, at 2:56 PM, K. Darcy Otto wrote:

I want to subclass Dependency and override a few things.  Can I do
this without modifying DeductionLine?

Perhaps you want to create a category instead?  That allows you to add
methods to Dependency without DeductionLine having to know about it.

A category would work fine, as long as you don't want to add any new instance variables to the Dependency class. Categories cannot members. They can override methods and define new methods though. The same goes for using the +[Class poseAs:] method.

If you do need to add instance variables and override methods, of course your best bet is to make a one-line modification to DependencyLine, and instantiate MyDependencySubclass instead of Dependency.

But if that's really not possible [Skanky Hack Alert!], you might be able to dive more deeply into the Objective-C runtime and change the names of your classes. If you look at <objc/runtime.h>, there is a name field in the class structure. If you do it at the right time, you should be able to change the names of Dependency and MyDependencySubclass so that your subclass is the new dependency. I haven't tried this though, and it's probably a bad idea. Also, the name field has been removed in Objective-C 2.0. So whether or not this is useful depends on what you're doing (private hack vs. commercial product with some future potential).

Cheers!
Dave Howell
Avatron Software

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to