Why use CustomComponent?

As a Vaadin newbie I have the following simple question. The manual says, after its discussion of Custom Component,

“You can also inherit any other components, such as layouts, to attain similar composition.”

and that is what I have been doing.

I can’t understand the CustomComponent’s raison d’etre. Is there any reason for using it, instead of just extending whatever layout you would have used as the CustomComponent’s composition root? Am I missing something obvious?


Matthew Fleming


You are right, there is no functional difference. It’s mostly for hiding implementation details, so that your custom component doesn’t automatically get all the features of the layout component which it extends and it could easily switch to use another layout later. Otherwise some users might begin to depend on the details. Much the same reason why there are private members and other information hiding features in Java.

The only other API differences are that CustomComponent doesn’t have the margin property nor layout click handlers, because it is a ComponentContainer, not a Layout. There’s not much point in not having those nice features.