Not sure I understand precisely, but try this.
Not sure I understand precisely, but try this: public interface MyInterface { int property; } public interface A : MyInterface { void MyMethod(); } public class AClass : A { public void MyMethod() { ... } int property; } public interface B : MyInterface { ICollection MyMethod(); } public class BClass : B { public ICollection MyMethod() { ... } int property; } In other words, interface A adds the method void MyMethod() to interface MyInterface, and interface B adds the method ICollection MyMethod() to interface MyInterface. Note that you still won't be able to call e.g. MyInterface object = new AClass(); object.MyMethod(); as MyMethod() won't be a member of MyInterface.
I tried but my problem comes when I want to use a code implemented for MyInterface and I can't cast between MyInterface and A, and MyInterface and B. I have to go now but I'll come back and try to explain it correctly. Thanks!
– maestro Nov 5 at 17:52.
Simply remove the part where interface A and B implement MyInterface. What's the point of MyInterface if you state you don't want to use it?
Remember that interfaces are contracts to a concrete implementation and that for it to make sense architecturally, any and all implementations should logically make use of the outlined properties and functions in the contract. Having 3 interfaces will give you what you're looking for and make more sense than trying to stretch 1.
No, you can't do that. The return type is part of the method signature. So if you don't implement ICollection MyMethod() you're not fulfilling the contract defined by MyInterface.
Why can't you simply implement MyMethod in AClass as returning null? I feel you'r going against what polymorphism is there for. You want to be able to use the interface, and call polimorphically on the classes, but you want that to return different things.
How do you plan to deal with the difference in returns? If the signature is different you have to manually adjust either before or after the call. If you return a null from AClass then you can adjust after the call.
And if you want to return a void, then I'd rather move the MyMethod out of MyInterface down to B and A, and do an AS A / B cast and do whatever you need to do in either case.
1) Use abstract class, so you can delegate implementation of particular method/property to the nested classes: public abstract class AClass : A { public void MyMethod() { ... } public abstract ICollection MyMethod(); } 2) Or extract ICollection MyMethod() in another interface which is not part of A inheritance tree.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.