Thanks for the response, I was looking to select members from a class
and set the based on an enum, some thing like [...]
In the code you posted, it's not clear to me why the method SetupChannel()
is intended to not know which member field it's setting. You're
duplicating the conditional logic, but for no apparent gain that I can see.
So, one suggestion would be to simply use a different member field
according to which case of your switch in SetupChannel() you're in.
That said, the other question your code example raises is why do you have
two member fields at all? They are both of type IChannel, and in an ideal
OOP design, any code that uses them wouldn't care _what_ IChannel
implementation they are. That's the whole point of having an interface..
By having two different variables, you not only introduce this question of
which one to assign during initialization, you also will necessarily have
to have conditionals every time you want to use one or the other to see
which one to use. A better OOP design would simply ignore the
implementation detail and use a single IChannel member field, in the usual
polymorphic way.
If you really want this kind of pre-selection during initialization, the
use of a delegate as I showed earlier certainly would work. But as I
mentioned, it's an awkward way to go about things, and I think in this
case there are at least a couple of clearly better approaches.
As an aside, I'm also a bit confused by the relationship between the two
"protocols", since HTTP and TCP aren't peers in the hierarchy of
protocols. But, I'll take as granted that you have a good reason for
that, since it's not what you asked about.
Pete