mardi 2 août 2016

Design factory for Java driver

I would like to create Factory class which returns Object based on String variable. For example:

public class BrowserFactory
{
    public BrowserFactory(String browser)
    {
        switch (browser.toLowerCase())
        {
            case "chrome":
            {
                new ChromeDriver();
                break;
            }
            case "firefox":
            {
                new FirefoxDriver();
                break;
            }
            case "explorer":
            {
                new InternetExplorerDriver();
                break;
            }
            case "edge":
            {
                new EdgeDriver();
                break;
            }
        }
    }
}

I would like to use it this way:

BrowserFactory sd = new BrowserFactory("chrome");

Can you propose some better way to design this code?

Aucun commentaire:

Enregistrer un commentaire