I'm looking for a way to share the implementation of two classes without exposing any details of that sharing. I was hoping to create this basic class structure:
- public interface MyInterface
- class MyCommonImpl : MyInterface
- public class MyImplA : MyCommonImpl
- public class MyImplB : MyCommonImpl
MyCommonImpl
implements the functions of MyInterface
and has one abstract function provided in MyImplA
and MyImplB
. A user of MyImplA
should not know about MyCommonImpl
in any fashion, it's just an implentation detail.
I've considered doing manual composition, but this involves copying a lot of code to forward the functions. It's also problematic since there are events implemented in MyCommonImpl
, and one of their parameters is a sender
. This requires putting a proxy handler and partially rewriting events. Basically composition would require more code than simply copy-pasting the entire MyCommonImpl
.
How can I do this without having to duplicate a lot of code?