I’m trying to organize my code flexible. So my application makes heavy use of interfaces. In my controller class I want to start the webcam preview on a certain control in the view. Implementations of ClientView and WebcamPreview rely on each other. So there is one specific WebcamPreview for WinForms and one for WPF. I ended with 2 possible ways:
Option 1:
Pros: Generics
Cons: Generic declarations bubble up to the top controller class, and I need to declare at least 3 generics in it. (Maybe I’m doing something wrong?)
interface IClientView<TSelf>
{
TSelf SelfControl { get; }
}
interface IWebcamPreview<TSelf>
{
void Start(TSelf selfControl);
}
Option 2:
Pros: Avoids to much generics
Cons: Directives; will compile different assemblies for WPF and WinForms
interface IClientView
{
#if WPF
ControlBase SelfControl { get; }
#else // WinForms
PictureBox SelfControl { get; }
#endif
}
interface IWebcamPreview
{
// analog
}
So how do I organize my code in order to support different UI frameworks?
Option 3: