Re: Multiple Inheritance
Re: Multiple Inheritance
- Subject: Re: Multiple Inheritance
- From: Ken Thomases <email@hidden>
- Date: Thu, 24 May 2012 10:35:46 -0500
On May 24, 2012, at 4:14 AM, Gerriet M. Denkmann wrote:
> I have an abstract class M with subclasses MAB, MAX, MXB.
>
> There are several lengthy methods A which are used in MAB and MAX, and others methods B which are used in MAB and MXB.
>
> Methods A use a property NSUInteger index.
> Class MXB has no such property, is has NSIndexSet *indices instead.
>
> Similar for methods B.
>
> Currently these common methods are present in both classes.
> But: this is less than perfect - meaning that each change has to be done twice.
>
> What to do?
> Have a file methodsA.m which is included in both MAB and MAX (and same for methodsB.m) ?
>
> Other, better solutions?
Perhaps this is a case calling for composition. Maybe a MAB and a MAX should own an A object, while a MAB and MXB should own a B object. The A object would implement the A methods and the index property. The B object would implement the B methods and whatever properties. If the A and B methods are part of the public interface of the subclasses, then they could implement thin wrappers that simply forward through to the internal objects. You could use protocols to enforce the requirement that the subclass implement the required interface faithfully, if you want.
Or, you can leverage the preprocessor as you suggest.
Regards,
Ken
_______________________________________________
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