Design Pattern Examples
Overview of object-oriented design patterns
DesignPatternExamples_python.composite.composite_exercise Namespace Reference

Functions

str Composite_Exercise_FormatEntry (FileDirEntry entry, int depth)
 Format the specified entry for display.
 
None Composite_Exercise_ShowEntry (FileDirEntry entry)
 Recursively display the contents of the hierarchical list of objects starting with the given object.
 
def Composite_Exercise ()
 Example of using the Composite Pattern.
 

Function Documentation

◆ Composite_Exercise()

def Composite_Exercise ( void  )

Example of using the Composite Pattern.

The Composite pattern is used when a collection of objects is to be formed in a hierarchical form where each object needs to be treated like any other object but some objects can contain other objects.

This example uses a file structure of file and directories to represent each object type.

Definition at line 66 of file composite_exercise.py.

References DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise_ShowEntry().

◆ Composite_Exercise_FormatEntry()

str Composite_Exercise_FormatEntry ( FileDirEntry  entry,
int  depth 
)

Format the specified entry for display.

This is a recursive call.

Parameters
entryThe FileDirEntry object to format
depthThe current recursion depth. This is used as leading space.
Returns
A string containing the formatted text for the given entry.

Definition at line 22 of file composite_exercise.py.

References DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise_FormatEntry().

Referenced by DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise_FormatEntry(), and DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise_ShowEntry().

◆ Composite_Exercise_ShowEntry()

None Composite_Exercise_ShowEntry ( FileDirEntry  entry)

Recursively display the contents of the hierarchical list of objects starting with the given object.

Parameters
entryThe file entry to display

Definition at line 50 of file composite_exercise.py.

References DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise_FormatEntry().

Referenced by DesignPatternExamples_python.composite.composite_exercise.Composite_Exercise().