jeudi 1 septembre 2016

Class

I have a scenario that (simplified) is as follows:

public static class Example
{
    public const int CONSTANT_VALUE = 1;

    public static Example<T> Create<T>(IEnumerable<T> argument)
        where T : class
    {
        return new Example<T>(argument);
    }
}

public class Example<T>
    where T : class
{
    public Example(IEnumerable<T> argument)
    {
        //Do Stuff
        if (something == Example.CONSTANT_VALUE)
        {
            //Do A Thing
        }
    }

    //Lots more code
}

The basic idea is that I can have static methods, constants, etc. available through the name of the class through the static class, while the actual implementation is in the type-argumented non-static class.

My question is whether or not this is a good way to set this up. Is there a way to put some static methods and constants that don't care what the type argument is on Example<T>? Is there otherwise a more recommended pattern? What I have works fine, but I wanted to know if there are other ways since this is the first time I've ended up doing something like this (not that it's conceptually new to me, just never had need).

Aucun commentaire:

Enregistrer un commentaire