C #: extension from more than 1 class

Suppose I have a ViewModel TabViewModelthat extends a ObservableObjectclass for ViewModels in the MVVM Foundation Framework. Then I also have EditorTabViewModelthat extends TabViewModel. Now I need to expand DependencyObjectto implement DependencyProperties. I can not extend more than 1 class. How can i implement this? I could have a "intermediate" class, for example ...

TabViewModel : ObservableObject

EditorTabViewModel : TabViewModel

DependentEditorTabViewModel : DependencyObject

but this is an extra class. Any better way to do this?

UPDATE

In fact, I can not do the above. DependentEditorTabViewModelstill need to extend EditorTabViewModel ... exceptDependencyObject

+5
source share
2 answers

C # does not support multiple inheritance . It is best to use interfaces rather than parent classes.

Even if you don’t have the ability to use interfaces (perhaps you don’t have access to the code), it is usually better to prefer composition over inheritance , do you really need to inherit both of these classes, or can you write with them?

+2
source

This is not an extra class if you are doing what you need. Here's how you do it:

DependentEditorTabViewModel : DependencyObject

TabViewModel : DependentEditorTabViewModel
+1
source

All Articles