Package pypat :: Package structural :: Module composite :: Class Composite
[hide private]
[frames] | no frames]

Class Composite

source code

object --+
         |
        Composite


Composite class as part of the Composite pattern.

- External Usage Documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Structural-Pattern-Usage}
- External Composite Pattern documentation: U{https://en.wikipedia.org/wiki/Composite_pattern}

Instance Methods [hide private]
 
__init__(self, interface)
Initialize a new Composite instance.
source code
 
add_component(self, component)
Add a component to this composite.
source code
 
remove_component(self, component)
Remove a component from this composite.
source code
 
_delegate(self, func_name)
Apply a function to all child components by function name.
source code
 
__getattr__(self, item)
Override getattr to delegate all function calls to children.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, interface)
(Constructor)

source code 

Initialize a new Composite instance.

Parameters:
  • interface (class) - The interface the all child components must adhere to when added to this composite.
Overrides: object.__init__

add_component(self, component)

source code 

Add a component to this composite.

Parameters:
  • component - The component to add to this Composite
Raises:
  • AttributeError - If the component does not adhere to this Composites interface.

remove_component(self, component)

source code 

Remove a component from this composite.

Parameters:
  • component - The component to remove from this Composite.

_delegate(self, func_name)

source code 

Apply a function to all child components by function name.

Parameters:
  • func_name (str) - The name of the function to call with all child components.
Raises:
  • AttributeError - If a child component does not have a callable function with the given name.

__getattr__(self, item)
(Qualification operator)

source code 

Override getattr to delegate all function calls to children.

Parameters:
  • item (str) - The function to call with this composites children components.
Returns:
A function that when called will call all child functions with the given function name.