Abstract factory pattern instead of generics - how?

Viewed 1352

I have a generic interface:

public interface IReader<T> where T: Result
{
   IEnumerable<T> ReadResults();
}

where Result is a base class and is extended into DetailedResult:

public class Result
{
    // ...
}

public class DetailedResult : Result
{
    // ... ...
}

Now I have two concrete types for IReader, each of this implementation returns different type, specific to the reader type:

public class DefaultResultReader<Result> : IReader<Result>
{
    IEnumerable<Result> ReadResults();
}

and

public class DetailedResultReader<DetailedResult> : IReader<DetailedResult>
{
    IEnumerable<DetailedResult> ReadResults();
}

The structure presented above uses generics. I would like to get rid of it if possible, and have some kind of a factory which would create a concrete implementation of IReader for me - DefaultResultReader.ReadResults() method must return Result while DetailedResultReader.ReadResults() must return DetailedResult

My question is how should the abstract factory look for this structure - how to design it so that I can create specific IReader object as requested ?

3 Answers
Related