+ 2
What is the best way to simulate multiple inheritance in C#?
I know that by default C# does not allow multiple inheritance. But is it possible to do it using Interfaces, Reflection, Dynamic, Roslin, etc?
5 odpowiedzi
+ 6
You can inherit only one class in c#. In addition to that you can inherit multiple interfaces but be careful not to violate the SOLID principles. If you inherit intefaces you must manually write the methods or properties etc.
You can also create an instance of a Unit of Work if you created one in your code somewhere. That helps mostly if you have mostly the same actions on a lot of code like CRUD operations.
Other than that I too am open to more knowledge that these.
+ 4
Interfaces
+ 3
Tugay Mandal the problem with this way is that when an instance of the Multiple class is passed to a method that expects an instance of the Driver class, because of the polymorphism, the method of the Multiple class must be executed if a true multiple inheritance is to be obtained , but this does not happen, the method that is executed is that of the Driver class.
https://code.sololearn.com/cTgS91pc4eYQ/#
+ 3
You can use this factory pattern for similar code.
https://code.sololearn.com/cS48XRijh034/?ref=app
+ 2
I thinl you can use one Iwork interface and 3 different classes with Working methods and make the multiple class a generic like Multiple<Ttype>(etc) and then call the classes and their corresponding methods.