Código Factory Method
public interface ProductReader {
    public DecodedProduct getDecodedProduct();
}
 
public class Product1Reader implements ProductReader {
    public DecodedProduct getDecodedProduct() {
        // ...
        return decodedProduct;
    }
}
 
public class Product2Reader implements ProductReader {
    public DecodedProduct getDecodedProduct() {
        // ...
        return decodedProduct;
    }
}


public class ProductReaderFactory {
    public static ProductReader getProductReader(InputStream is) {
        int ProductType = determineProductType(is);
 
        switch (imageType) {
            case ProductReaderFactory.Product1:
                return new Product1Reader(is);
            case ProductReaderFactory.Product2:
                return new Product2Reader(is);
            // etc.
        }
    }
}