Class Composite

java.lang.Object
Structural.Composite.Composite
All Implemented Interfaces:
Component

public class Composite extends Object implements Component
Represents the Composite object in the Composite pattern. A Composite can contain both Leaf and other Composite objects.
  • Constructor Details

    • Composite

      public Composite(String name)
      Constructor for the Composite.
      Parameters:
      name - The name of the Composite.
  • Method Details

    • operation

      public void operation()
      Performs the operation on the Composite and its children.
      Specified by:
      operation in interface Component
    • add

      public void add(Component component)
      Adds a child component to the Composite.
      Specified by:
      add in interface Component
      Parameters:
      component - The child component to add.
    • remove

      public void remove(Component component)
      Removes a child component from the Composite.
      Specified by:
      remove in interface Component
      Parameters:
      component - The child component to remove.
    • getChild

      public Component getChild(int index)
      Retrieves a child component at the specified index.
      Specified by:
      getChild in interface Component
      Parameters:
      index - The index of the child component to retrieve.
      Returns:
      The child component.