Inheritance and the 'Curiously Recurring Template Pattern'

c#, generics, inheritance, polymorphism

Solution

Have `SqlBrowse<T>` implement a non-generic `SqlBrowse` interface (or abstract class), and then write

public SqlBrowse People { get; set; }

It's hard to tell what changes that will entail to your classes because we don't have their definitions.

Problem

In an MVC project I have the following classes: ``` public abstract class Browse<T> where T : Browse<T> public abstract class SqlBrowse<T> : Browse<T> where T : Browse<T> public class SqlBrowseBoys : SqlBrowse<SqlBrowseBoys> public class SqlBrowseGirls : SqlBrowse<SqlBrowseGirls> ``` and the following view model ``` public class BrowseViewModel { public [INTERFACE] People { get; set; } } ``` but I need an interface/class in the position labelled [INTERFACE] that can take both SqlBrowseBoys and SqlBrowseGirls so I can use BrowseViewModel in multiple places. I'd love it if someone could show me how as my brain is now tied in knots. I suspect this will require some change(s) to the classes and that's fine but I currently have no clue what that will be. Many, many thanks.

Original source