0

I wanna make generic tree.

I have base class like:

public class TreeItemModelBase<T>
{
    protected List<T> children;
    ...
}

and derived classes like:

public class StorageTreeItemModel : TreeItemModelBase<StorageTreeItemModel>
{
     ...
}

Is this OK? I am not sure if I can use generic like this (Use StorageTreeItemModel like T).

Thank you

Jakub Čermoch
  • 431
  • 1
  • 9
  • 20
  • May be of interest: http://stackoverflow.com/questions/66893/tree-data-structure-in-c-sharp – nvoigt Nov 26 '16 at 10:27

1 Answers1

0

Yes, inheriting a generic class or implementing a generic interface using your own class as a generic type parameter is fine.

Implementations that avoid this are available and personally I think they are easier to understand, but as long as you are happy with the code, from a technical side there is nothing wrong with it.

nvoigt
  • 75,013
  • 26
  • 93
  • 142