Answer the question
In order to leave comments, you need to log in
Which pattern is better to use when you need to implement methods from different classes?
Please tell me:
There is an interface/abstract class A
It has 2 methods without implementation of M1 and M2
There is a class B inherited from A
There is a class C inherited from A
Both have their own implementation of methods M1 and M2
Suppose I need to create a class D, in where M1 contains an implementation of class B, and method M2 contains an implementation of class C.
There is no multiple inheritance in C#. Is there any generally accepted solution or ready-made pattern for such situations?
Answer the question
In order to leave comments, you need to log in
there is a great tool - extensions .. create any orgy ...
ps By the way, extensions wean you from the habit of producing extra classes due to 1-2-3 methods ..;))
Suppose I need to create a class D, in which M1 contains the implementation of class A, and the method M2 contains the implementation of class B.
not knowing how it happened)
Perhaps because of the overloaded interface. (it's very important to stick to thin interfaces. e.g. interface M1 interface M2)
But allow (maybe) so
D implements the interface, but delegates the execution of M1 to class B, M2 to class C
i.e. delegation pattern
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question