Computer scienceFundamentalsEssentialsSoftware constructionDesign patternsStructural design patterns

Composite pattern

Objects in code

Report a typo

Here's a simple example of the composite pattern in pseudocode:

interface ComputerParts is
  method connect()


class SystemUnit implements ComputerPart is
  field parts: array of ComputerParts

  constructor of SystemUnit ...

  method add(part: ComputerPart) is ...

  method connect() is
    foreach (part in parts) do
      part.connect()


class GPU implements ComputerParts is
  constructor of GPU ...

  method draw() is ...
 
  method connect() is ...


class HDD implements ComputerParts is
  constructor of HDD...

  method boot() is ...
 
  method connect() is ...

  method store() is ...

Sort classes of this snippet by their types.

Choose one option for each row
CompositeLeafComponent
ComputerParts
SystemUnit
GPU
HDD
___

Create a free account to access the full topic