Generics Best Practice

This is the Microsoft listed best practice for generics.

I agree with the following post. Here Richard Birkby recommends subclassing generics before using them.

His argument is that this make it easier to extend (which is a good idea) but I would also recommend subclassing to reduce the repetitive nature of the code:

For example:

public class foo

{

public List<int> Bar

{

get {return _Bar;}

}

private List<int> _Bar;

}

 

Would be more cleanly written as:

public class IntList : List<int> {}

public class foo

{

public IntList Bar

{

get {return _Bar;}

}

private IntList _Bar;

}

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s