I want to create the following strategy template in conjunction with Factory, but I want it to be typical. I have done the following so far:
public interface Parser<T> { public Collection<T> parse(ResultSet resultSet); } public class AParser implements Parser<String> { @Override public Collection<String> parse(ResultSet resultSet) {
In general, everything that I try, somewhere I will have an uncontrolled cast. Does anyone have an idea how I can refactor code for types?
Checking Effective Java I also came across this pattern:
public final class ParserFactory { private ParserFactory() { } private static class AParser implements Parser<String> { @Override public Collection<String> parse(ResultSet resultSet) {
So now I can use as suggested by Ingo
public <T> Collection<T> getResults(String query, Parser<T> p)
but
getResults("query", ParserFactory.APARSER);
Or will it be better with listings?
java generics strategy-pattern factory-pattern
Chrisgeo
source share