2 added 148 characters in body
source | link

In my project I have different types of entities.
I get the data for these entities in text files from a 3rd party.
I've written a class to read and parse these text files, using the strategy pattern.
The method in this class must return different entity types so I've made the entire class generic - something like this:

public class Parser<T>
{
    public IStrategy<T> strategy { get;set;}

    public IEnumerable<T> LoadFromFile()
    { 
        // implementation details, not interesting
    }
}

But the problem is that now I need a new instance of Parser for every entity I load, so I changed my initial implementation into this:

public class Parser
{
    public IEnumerable<T> LoadFromFile(IStrategy<T> strategy)
    {
        // implementation details, not interesting
    }
}

So, is this still considered as an implementation of the strategy pattern?

If not, is there any way I could return IEnumerable<T> without having to specify what type T actually is anywhere but in the IStrategy<T>?

In my project I have different types of entities.
I get the data for these entities in text files from a 3rd party.
I've written a class to read and parse these text files, using the strategy pattern.
The method in this class must return different entity types so I've made the entire class generic - something like this:

public class Parser<T>
{
    public IStrategy<T> strategy { get;set;}

    public IEnumerable<T> LoadFromFile()
    { 
        // implementation details, not interesting
    }
}

But the problem is that now I need a new instance of Parser for every entity I load, so I changed my initial implementation into this:

public class Parser
{
    public IEnumerable<T> LoadFromFile(IStrategy<T> strategy)
    {
        // implementation details, not interesting
    }
}

So, is this still considered as an implementation of the strategy pattern?

In my project I have different types of entities.
I get the data for these entities in text files from a 3rd party.
I've written a class to read and parse these text files, using the strategy pattern.
The method in this class must return different entity types so I've made the entire class generic - something like this:

public class Parser<T>
{
    public IStrategy<T> strategy { get;set;}

    public IEnumerable<T> LoadFromFile()
    { 
        // implementation details, not interesting
    }
}

But the problem is that now I need a new instance of Parser for every entity I load, so I changed my initial implementation into this:

public class Parser
{
    public IEnumerable<T> LoadFromFile(IStrategy<T> strategy)
    {
        // implementation details, not interesting
    }
}

So, is this still considered as an implementation of the strategy pattern?

If not, is there any way I could return IEnumerable<T> without having to specify what type T actually is anywhere but in the IStrategy<T>?

1
source | link

Is this still considered an implementation of the strategy pattern?

In my project I have different types of entities.
I get the data for these entities in text files from a 3rd party.
I've written a class to read and parse these text files, using the strategy pattern.
The method in this class must return different entity types so I've made the entire class generic - something like this:

public class Parser<T>
{
    public IStrategy<T> strategy { get;set;}

    public IEnumerable<T> LoadFromFile()
    { 
        // implementation details, not interesting
    }
}

But the problem is that now I need a new instance of Parser for every entity I load, so I changed my initial implementation into this:

public class Parser
{
    public IEnumerable<T> LoadFromFile(IStrategy<T> strategy)
    {
        // implementation details, not interesting
    }
}

So, is this still considered as an implementation of the strategy pattern?