Challenge: Solution Review
This lesson will explain the solution to the problem from the previous coding challenge.
We'll cover the following...
Solution #
Explanation
The illustration below provides a visualization of the hierarchy of the classes in the code above:
From the illustration above, you can see that the pattern consists of the following:
-
Component:
Directoryclass which contains the abstract methodsgetLastmodified,getSize, andgetName. A directory has the following properties:name,lastModified, andsize. -
Leaf:
FileisDirectory's subclass. It is the leaf component as it has no children. It defines the functionsgetLastmodified,getSize, andgetNamereturning thename,size, andlastModifiedtime of a file. -
Composite
Folderis the composite subclass. It has other files as its children.
Let’s start to discuss each component.
...