vendredi 20 janvier 2017

Would it be preferable to

Instead of using the typical Factory Method pattern when you want subclasses to produce objects, like this:

@Override
public Thing getThing(){
    return new OtherThing();
}

Would it be a good idea to instead have a java.util.function.Supplier<Thing> field that is assigned from the constructor? (Same question with the factory method taking an argument vs. a Function instead)

That way you wouldn't have to extend the original class, but just specify through the constructor. But I guess you would still have to extend your own Supplier/Function, so I'm not sure if it'd still be beneficial.

Aucun commentaire:

Enregistrer un commentaire