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

Re: Subclassing


  • Subject: Re: Subclassing
  • From: Dave Howell <email@hidden>
  • Date: Sat, 19 Apr 2008 10:18:08 -0700


On Apr 18, 2008, at 5:54 PM, Jack Repenning <email@hidden> 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 (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: Get list of possible applications
  • Next by Date: Binding NSButton enabled state
  • Previous by thread: Re: Subclassing
  • Next by thread: editing in a custom NSView
  • Index(es):
    • Date
    • Thread