C # Design Pattern for 2 classes with the same implementation but with a different base class

Take two base classes A and B, which are similar, but preferable to distinguish. Each of them has a subclass (A 'and B') that adds the same functionality and members to their respective classes. Is there a design pattern that allows me not to duplicate code in 'and B'?

I looked at Bridgeand Decorator, but I do not see how they will work.

Thanks Rob

+3
source share
5 answers

Could you use composition and refactor the common code into another C class?

+11
source

A B, , . (A ' B '), .

. , .

, , - , , Decorator - , , .

A ' B'. . , . ', B'.

, .

+2

. ' B'.

+2

add the same functionality and members to their respective classes. , . , - Provider? http://msdn.microsoft.com/en-us/library/ms972319.aspx

0

mixins , . #. , mixins, .

: mixins #?

0

Source: https://habr.com/ru/post/1777998/


All Articles