leogtzr
3/2/2017 - 5:34 AM

factory_pattern_java8.java

enum ShapeType {
    CIRCLE {
        @Override
        public Supplier<Shape> create() {
            return Circle::new;
        }
    },
    RECTANGLE {
        @Override
        public Supplier<Shape> create() {
            return Rectangle::new;
        }
    }
    ;
    
    abstract Supplier<Shape> create();
    
}

final class Factory {
    
    private Factory() {}
    
    public static Shape getShape(final ShapeType type) {
        return type.create().get();
    }
    
}