Interface Design : Hiding Members
-
I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple
-
I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple
public interface IInterfaceA
{
void MethodA();
void MethodB();
}public class X : IInterfaceA
{
void IInterfaceA.MethodA() { }
void IInterfaceA.MethodB() { }public void MethodC() { } public void MethodD(){}
}
-
I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple
-
Could you just do this:
interface A { Method A Method B } interface B { Method C Method D } Class X: Interface A, Interface B { ... etc. } And then have user only instantiate one of type a or type b.
-
Hmm, I'm not a true VBer :), but you might think of hidding the interface's methods in the implementation class with the low access level like
private
orprotected
:Public Interface IInterfaceA
Sub MethodA()
Sub MethodB()
End InterfacePublic Class X
Implements IInterfaceAPrivate Sub MethodA() Implements IInterfaceA.MethodA End Sub Protected Sub MethodB() Implements IInterfaceA.MethodB End Sub Public Sub MethodC() End Sub Public Sub MethodD() End Sub
End Class
Btw, for this kind of question, you might want to ask in the VB.NET forum.
-
I have an Interface say InterfaceA which has two method declarations Method A & Method B The above interface is implemented by Class X Additionally Class X also has two more methods Method C & Method D If I instantiate an object of Class X, I want only Method C and Method D to be exposed. The Method A and Method B should not be exposed by default to the user unless he explicitly casts it..How do I design such an interface and how will the user do the 'casting' if required If anybody knows how to do this..pls help Dimple