• 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: How do I give a set of methods to some objects but not others?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I give a set of methods to some objects but not others?


  • Subject: Re: How do I give a set of methods to some objects but not others?
  • From: John Stiles <email@hidden>
  • Date: Fri, 24 Nov 2006 07:31:38 -0800

Can you inject a shared class in the middle of the subclassing chain?
e.g.:

NSObject -> OtherObjectYouDidntWrite -> YourAccessorClass -> YourClassA

NSObject -> OtherObjectYouDidntWrite -> YourAccessorClass -> YourClassB

NSObject -> OtherObjectYouDidntWrite -> YourAccessorClass -> YourClassC

Your accessor class could contain the accessor functions (and data) for all the shared functions for your class A, B and C.
There might be a snag here which I'm not thinking of, but it seems like a good solution at the moment :)



Alan Smith wrote:
Hi all,

I have a bunch of classes that I want to be able to use a set of
methods. They'll fulfill a formal protocol in this way. The problem is
that they can't inherit the methods because they're already inheriting
from other objects that I didn't write and there is no multiple
inheritance in ObjC.

I could write a NSObject subclass with the methods in it and then pose
it as NSObject. But then all classes would have access to those
methods and I don't want just anyone using them because they would
cause a memory leak if used improperly.

I could write a category on NSObject and import it but then I'd have
to write a method for each method in the category calling the
respective one in the category. This would be redundant and not the
OOP way.

The reason I don't write the methods over-and-over again in each class
is because they would all be the same, exactly the same. They're
accessor methods and so they would be the same. I want to write the
methods only once and not multiple times.

This may be pretty confusing so if you have any questions please ask me.

Thanks in advance, Alan


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Re: How do I give a set of methods to some objects but not others?
      • From: "Alan Smith" <email@hidden>
References: 
 >How do I give a set of methods to some objects but not others? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: How do I give a set of methods to some objects but not others?
  • Next by Date: Re: Re: How do I give a set of methods to some objects but not others?
  • Previous by thread: How do I give a set of methods to some objects but not others?
  • Next by thread: Re: Re: How do I give a set of methods to some objects but not others?
  • Index(es):
    • Date
    • Thread