I have three classes that interact as follows. Class A
contains a private member of type Class B
. It also contains a method to which an object of type ClassC
is passed. This method then calls a method on ClassC
, passing to it a particular interface (ClassBInterface1
) of its member of type ClassB
:
ClassA
{
void Foo(ClassC ObjectC)
{
ObjectC.Bar((ClassBInterface1) ObjectB);
}
ClassB ObjectB;
}
My question is: ClassA
does not need to access the methods of ClassB
defined in Interface1
. Therefore, in my view, it would be more elegant if the member of ClassA
was of type ClassBInterface2
, rather than ClassB
. Is it possible to do this, while still passing B to C under Interface1
?
The only way I can think of is to typecast ClassBInterface2
to ClassB
and back to ClassBInterface1
in the Bar method in ClassA
.
Is this the best way to do it? Or should I just leave it as it is?
Thanks a lot for any help.