dimanche 20 novembre 2016

Java - What is the easiest or more logical way to transform this code in a real factory design pattern

i'm currently using a class to generate some images. I called this class ImageFactory but after some research i don't think it correspond at all to any of the factory design pattern (method, static method or abstract).

I have looked the "real" factory design pattern and would like to change my code to use on of them (factory method, static factory method or abstract factory).

Which one should i go for and how should i proceed ?

Here is the (simplified) code of my "Factory" :

public class ImageFactory
{

    public CelluleImageFactory()
    {
    }

    public Image getImageA () throws IOException
    {
        return ImageIO.read(new File("imgA.png"));
    }


    public Image getImageB(String size, String color) throws IOException
    {

        return ImageIO.read(new File("imgB-" + size + "-" + color + ".png"));
     }

    public Image getImageC (String color) throws IOException
    {

        return ImageIO.read(new File("imgC-"+ color + ".png"));
    }
}

Aucun commentaire:

Enregistrer un commentaire