I'm quite new to C# but I have quite good C++ knowledge. From C++ I'm used that something like this works:
class Base1 {};
class Derived1 : Base1 {};
class Base2 {
Base1 foo();
};
class Derived2 {
Derived1 foo();
};
which I know under the term Covariance. The piece of code might miss something but I hope you get what I want to say. As I tried to produce something like that in C# with override and stuff, the Compiler complained that the type had to be the same. like this:
class Base1 {};
class Derived1 : Base1 {};
class Base2 {
Base1 foo();
};
class Derived2 {
Base1 foo();
};
Might that lead to any problems? Of course as I am the programmer of function foo I can assure there will always be a Derived1 returned. But whoever calls my function doesn't know that.
I have a project in which I have some Manager classes, for which I wanted to use an Interface IManager (it's my own class, not any from .NET if there exists any with that name), because they all have to implement a method Load() for example. Load() always returns a an Object, that is managed by that certain Manager. If every Manager implements IManager, all of them would get the Interface
ManagableObject Load();
Is that good, bad? Or even better, is there any workaround?
I also read that it worked with templates, but only like this I guess:
List<Base1> myList;
myList.push_back(new Derived1());
Or can I use List as return type in Base1 and List in class Derived2? That would be ok too.
Thanks and best regards, Expecto