If B really needs to implement IA , then B must redefine each of the interface methods one by one, even if each implementation is just a call to the implementation of the encapsulated member A
However, there is a lazy way that can prevent you from all this tedious material and which can be considered almost the same from a practical point of view:
class Program { static void Main(string[] args) { CatOwner Bob = new CatOwner(); Console.WriteLine(((Cat)Bob).Cry); Console.ReadKey(); } } interface ICry { string Cry { get; } } class Cat : ICry { public string Cry { get { return "Meow !"; } } } class CatOwner { private Cat _MyCat; public CatOwner() { _MyCat = new Cat(); } public static implicit operator Cat(CatOwner po) { return po._MyCat; } }
CatOwner does not actually implement Cry , as the owner of the cat is not the one who meows: his cat does. But as an approximation, we could assume that by demanding that the owner of the cat cry, we, of course, imply that this requirement is actually aimed at his cat, and not at the owner himself. Then we βthrow the cat owner to his cat,β and then we can make it Cry .
It's pretty funny, no ?:-)
Edit:
However, Magnus's answer is very worth considering IMHO. It looks more logical and cleaner if you pass the member perfectly, given the semantic context. My solution may be interesting if B is just an expanded variety of A that cannot be inherited (sealed) or in such a specific context ... It really depends on the context and semantic restrictions ...
source share