Re: Multiple Inheritence (Was: Is _objc_flush_caches_(Class) necessary to swizzle methods?)
Re: Multiple Inheritence (Was: Is _objc_flush_caches_(Class) necessary to swizzle methods?)
- Subject: Re: Multiple Inheritence (Was: Is _objc_flush_caches_(Class) necessary to swizzle methods?)
- From: Ondra Cada <email@hidden>
- Date: Sat, 25 Sep 2004 16:36:50 +0200
On 25.9.2004, at 5:32, DumberThanDanQuayle wrote:
This is multiple inheritance type of problem, but a weaker one. It
does not require anything beyond protocols to achieve alternative
common appearances for class. More clearly, I want these classes to
have a single common implantation of like methods, so when I modify
them I do not have to scrounge the source files and make redundant
changes. I am want the consistency of these implementation to be
explicit.
But these classes need to not appear actually have multiple
super-classes. I have a very well defined class hierarchy and I can
not change it merely for the freedom to have only one implementations
of ancillary protocols. I think I have found my simple solution which
writing common method implementations in a separate file and using the
C preprocessor macro "#include" to insert that text into my classes
where necessary like this:
That's not the best way, IMHO :)
Anyway, in such a situation, I would indeed first consider
re-factoring, for the sole fact you need *the same implementation*
(unlike the same interface) for intrinsically different classes kind of
hints the hierarchy might be flawed. It looks somewhat like you may be
using the class hierarchy for something another feature (formal
protocol, embedding&forwarding, class clusters, whatever) would serve
better, with the result of the hierarchy lacking where you would need
it :)
If it is not so, well, as I've already written, I would find a common
ancestor and implement the functionality using a category there. Or
perhaps I would follow Tor Manders' advice, or use a combination of
them.
The idea presented in the code snippet above, that is writing
individual method or whole protocol implementations in a separate file
and the using the C preprocessor "#include" directives to insert that
text into class definitions where need, seems to work very well and
has no serious drawbacks
Well, depends on what "serious" means. You get one code at multiple
places. If you put a breakpoint there, it would work for one class
only, not for the other ones. To change somewhat the behaviour in
future without recompilation (using techniques like poseAsClassing or
categories) would be quite on the ugly side.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden