Implementing a factory

How about a factory of components? The following is an implementation of a factory with a method that returns a Component:

public class LoginFormFactory {

    public static Component getComponent() {

        ... create and configure all required components

        return new VerticalLayout(
                username, password, button, rememberMe);
    }
}

This hides the implementation details but also makes it more difficult and complex to offer functionality to the clients. For example, how would clients of the class get the username or password values introduced by the user in the form? One option is to implement getters in the factory class, but that would require some more adjustments in the LoginFormFactory class. At the end of the day, this kind of implementation would require you to implement (and maintain) two highly coupled classes for a single custom component. Not a very good idea.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset