Design Pattern Examples
Overview of object-oriented design patterns
Composite_Exercise Class Reference

Example of using the Composite Pattern in C#. More...

Collaboration diagram for Composite_Exercise:
Collaboration graph

Public Member Functions

void Run ()
 Executes the example for the Composite Pattern in C#.
 

Private Member Functions

string Composite_Exercise_FormatEntry (FileDirEntry entry, int depth)
 Format the specified entry for display.
 
void Composite_Exercise_ShowEntry (FileDirEntry entry)
 Recursively display the contents of the hierarchical list of objects starting with the given object.
 

Detailed Description

Example of using the Composite Pattern in C#.

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 22 of file Composite_Exercise.cs.

Member Function Documentation

◆ Composite_Exercise_FormatEntry()

string Composite_Exercise_FormatEntry ( FileDirEntry  entry,
int  depth 
)
inlineprivate

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 34 of file Composite_Exercise.cs.

References FileDirEntry.Children, Composite_Exercise.Composite_Exercise_FormatEntry(), FileDirEntry.FileDirType, FileDirEntry.Length, FileDirEntry.Name, and FileDirEntry.WhenModified.

Referenced by Composite_Exercise.Composite_Exercise_FormatEntry(), and Composite_Exercise.Composite_Exercise_ShowEntry().

◆ Composite_Exercise_ShowEntry()

void Composite_Exercise_ShowEntry ( FileDirEntry  entry)
inlineprivate

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

Parameters
entry

Definition at line 69 of file Composite_Exercise.cs.

References Composite_Exercise.Composite_Exercise_FormatEntry().

Referenced by Composite_Exercise.Run().

◆ Run()

void Run ( )
inline

Executes the example for the Composite Pattern in C#.

Definition at line 80 of file Composite_Exercise.cs.

References Composite_Exercise.Composite_Exercise_ShowEntry(), and Composite_FileAccess.GetEntry().

Referenced by Program.Run().


The documentation for this class was generated from the following file: