Using composition to develop custom components

If extending VerticalLayout is a problem, a possible solution is to not extend any class at all. However, in that case, we wouldn't get a Component, but a class of which instances cannot be added to the components tree. What about extending a more suitable component in the hierarchy? Let's start with interfaces. The following figure shows some of the top interfaces in the hierarchy:

Going up the hierarchy, we find the Component interface which has more than 20 methods that would require an implementation. The other interfaces inherit these 20+ methods and add some more. Fortunately, Vaadin provides abstract implementations for these interfaces. The following figure shows some of the equivalent implementations:

AbstractComponent is the default implementation of Component. Many Vaadin components directly extend this class. It's not a convenient class for the login form, though, since it's too general and doesn't offer methods to add other components to it. AbstractField and AbstractListing can be discarded as well because the login form is not just a field showing a value or a list of values, respectively.

The next candidates are the AbstractSingleComponentContainer, AbstractComponentContainer, and AbstractLayout classes. These classes help with the implementation of layouts, but as we discussed previously, a login form shouldn't look like a layout to the external world.

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

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