vendredi 31 août 2018

Using the Builder Pattern to returned a transformed argument

I have a script that passes many optional flags on a text image and saves the resulting transformations as an output. However, the script is written in bash and I need it to fit into our Java stack.

So I looked around and I heard that a Builder pattern is great for optional arguments (I've used them before without even realizing it). So I'm trying to create a Builder to solve my problem but Builders only return themselves. They aren't supposed to return any other type. One person recommended I just call .getImage() instead of .build() but I'm not sure if that's proper. This is what I have now for my theoretical TextCleaner class:

BufferedImage img = new TextCleaner.Builder("Capture1.png")
        .convertGreyScale()
        .enhance(Enhance.STRETCH)
        .filterSize(15)
        .offset(20);
        .getImage();

What should I do?

Aucun commentaire:

Enregistrer un commentaire