Re: How do I give a set of methods to some objects but not others?
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: Daniel Jalkut <email@hidden>
- Date: Fri, 24 Nov 2006 14:43:55 -0500
Hi Alan - as Mike Abdullah stated, this sounds like a perfect use for
formal protocols. You said it yourself in the opening paragraph :)
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
Articles/chapter_4_section_7.html#//apple_ref/doc/uid/TP30001163-CH7-
BAJJABHJ
A formal protocol declared as "MySpecialMethods" would then be
imposed on any arbitrary action by declaring it like this:
@interface MyObject : NSObject <MySpecialMethods>
Fun stuff. Enjoy.
Daniel
On Nov 24, 2006, at 10:20 AM, 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
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"When the World realizes that religion really is unnecessary, then it
shall evolve."
_______________________________________________
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:
sweater.com
This email sent to email@hidden
_______________________________________________
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