Inheritance and the Curiously Repeating Pattern

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 presentation model

public class BrowseViewModel
{
    public [INTERFACE] People { get; set; }
}

but I need an interface / class in the position labeled [INTERFACE], which can accept both SqlBrowseBoys and SqlBrowseGirls, so I can use BrowseViewModel in several places.

I would love it if someone could show me how my brain is now connected by nodes. I suspect that this will require some changes (and), and that’s fine, but at the moment I don’t know what it will be.

Many, many thanks.

+3
source share
1 answer

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

public SqlBrowse People { get; set; }

, , .

+3

All Articles