Interface Component

All Known Implementing Classes:
Composite, Leaf

public interface Component
The Component interface declares common operations for both leaf and composite objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    add(Component component)
    Adds a child component.
    default Component
    getChild(int index)
    Retrieves a child component at the specified index.
    void
    Performs an operation on the component.
    default void
    remove(Component component)
    Removes a child component.
  • Method Details

    • operation

      void operation()
      Performs an operation on the component.
    • add

      default void add(Component component)
      Adds a child component. This method is optional and can throw UnsupportedOperationException for leaf nodes.
      Parameters:
      component - The child component to add.
    • remove

      default void remove(Component component)
      Removes a child component. This method is optional and can throw UnsupportedOperationException for leaf nodes.
      Parameters:
      component - The child component to remove.
    • getChild

      default Component getChild(int index)
      Retrieves a child component at the specified index. This method is optional and can throw UnsupportedOperationException for leaf nodes.
      Parameters:
      index - The index of the child component to retrieve.
      Returns:
      The child component.