Extending Composite vs Component

In the Vaadin Business Starter app, there is a component called DetailsDrawer that looks like this:

public class DetailsDrawer extends Composite<FlexLayout>
        implements HasStyle, HasSize {

    ...
    
}

I’m curious as to what the benefit of making DetailsDrawer extend Composite<FlexLayout> is. Why can’t it just extend Component? Also, what is the point of having it imlement HasSize and HasStyle? I don’t see it overriding any of those interfaces’ default methods.

It’s mostly a matter of what kind of server-side API you want to expose. From the JavaDoc:

/**
 * A composite encapsulates a {@link Component} tree to allow creation of new
 * components by composing existing components. By encapsulating the component,
 * its API can be hidden or presented in a different way for the user of the
 * composite.
 * <p>
 * The encapsulated component tree is available through {@link #getContent()}.
 * Composite will by default look at the generic type declaration of its
 * subclass to find the content type and create an instance if the type has a
 * no-args constructor. You can also override {@link #initContent()} to manually
 * create the component tree. The encapsulated component itself can contain more
 * components.
 * <p>
 * Composite is a way to hide API on the server side. It does not contribute any
 * element to the {@link Element} tree.

HasSize and HasStyle have helpful default methods for setting sizes and styles respectively.

Thanks, what about DetailsDrawer extending Composite and not Component?

DetailsDrawer overrides no Composite methods, and from what I can tell, no other classes in the Business Starter App invoke Composite methods via a DetailsDrawer instance…

I know there’s a reason, but I’m not understanding why I couldn’t just make DetailsDrawer look like:

// Extend Component, not Composite<FlexBoxLayout>
public class DetailsDrawer extends Component
        implements HasStyle, HasSize {

    private static final String CLASS_NAME = "details-drawer";

    private final FlexBoxLayout header;
    private final FlexBoxLayout content;
    private final FlexBoxLayout footer;

    ...

So is there any particular reason why DetailsDrawer can’t extend Component? I’m only asking so I understand when/where to use Composite subclasses on my own.