Here's the original problem. There are two classes: Protocol and, say, ProtocolUser (which actully uses the Protocol class instance). Now, I need to support multiple protocols, whose feature sets only partly intersect, doing similar but not equal things. I grouped the features into several interfaces. That is:
interface IA {}
interface IB {}
interface IC {}
interface IP {};
class P_AB : IP, IA, IB {}
class P_AC : IP, IA, IC {}
class P_BC : IP, IB,IC {}
class P_User
{
IP m_p;
??? // needs to use m_p via IA, IB or IC, depending on which are supported
}
And the most vexed part: the protocols are to be switched on-the-fly. Methods of P_User will have to choose which interfaces to operate on, depending on which will be supported by the call time.
The initial plan was to rely on is & as operators. But it does look suspiciously cumbersome. The only alternative I see is to invent some kind of "CanDoThis / CanDoThat" infrastructure, but that doesn't differ much from a plain is.
Are there any helpful patterns I'm unaware of?