This page uses Python to implement an Adapter that displays a directory tree.
TreeDisplay is an abstract class that has two abstract methods GetChildren() and CreateGraphicNode(). The sample uses raise in both abstract methods to notify a programmer that the both are abstract that must be implemented in a derived class.
DirectoryTreeDisplay1 is an Adapter that adapts Python OS package (Adaptee). GetChildren() uses Python OS package to get directory tree. CreateGraphicNode() transforms directory tree to readable text.
Test1() is a test function that tests DirectoryTreeDisplay1 ()
Below is a results after running the Python program in MacBook.
$ python ./DesignPattern/Adapter/TreeDisplay.py
Test2() tests the new Adapter.
The better style of the directory tree displays as below after running the Python program.
The below class diagram summarizes the implementation.
-Count