Re: Multiple Inheritance via protocol extensions in Swift

2016-09-06 Thread Quincey Morris
On Sep 6, 2016, at 23:26 , Gerriet M. Denkmann wrote: > > Anything to be done here? Or should I just forget about protocol extensions? There’s nothing really wrong here, it’s just that it doesn’t work like you think. There is no *inheritance* of protocol default implementations, which means t

Multiple Inheritance via protocol extensions in Swift

2016-09-06 Thread Gerriet M. Denkmann
Trying to eliminate code duplication I tried to use protocol extensions. But I ran into a rather grave problem. This probably is “working as documented”. But it surely it is not working like I hoped it would. Here is a Playground example: protocol Number { func aFunction() -> Int } exte

Re: Multiple Inheritance

2012-05-24 Thread Jens Alfke
On May 24, 2012, at 4:15 AM, Gerriet M. Denkmann wrote: > How do I avoid duplicating method implementations using a protocol? You don't, other than by using techniques like the ones I described. Protocols are just for the convenience (and type-safety) of the _users_ of a class; they don't real

Re: Multiple Inheritance

2012-05-24 Thread Gerriet M. Denkmann
On 24 May 2012, at 17:37, Graham Cox wrote: > Turn it into two separate protocols instead, and adopt whichever protocols > are needed in the concrete implementations. Or if one protocol is a superset > of the other, a protocol can extend another. I thought that a protocol only declares methods

Re: Multiple Inheritance

2012-05-24 Thread Jens Alfke
Implement both A and B in the base class M, but don't declare them in its @interface. Then MAB and MAX can both declare method A and have implementations that just call super. Likewise for B. Or, factor out A into a helper class, and similarly for B. Then have MAB and MAX instantiate an A helpe

Re: Multiple Inheritance

2012-05-24 Thread Ken Thomases
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

Re: Multiple Inheritance

2012-05-24 Thread Thomas Davie
Implement abstract classes that implement the methods, then use the runtime to copy the methods into the classes that should have them in +initialize. Bob On 24 May 2012, at 10:14, Gerriet M. Denkmann wrote: > I have an abstract class M with subclasses MAB, MAX, MXB. > > There are several leng

Re: Multiple Inheritance

2012-05-24 Thread Graham Cox
Turn it into two separate protocols instead, and adopt whichever protocols are needed in the concrete implementations. Or if one protocol is a superset of the other, a protocol can extend another. --Graham On 24/05/2012, at 7:14 PM, Gerriet M. Denkmann wrote: > Other, better solutions?

Multiple Inheritance

2012-05-24 Thread Gerriet M. Denkmann
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