honeytrap.devexercisescomposite.javaSettings
Description

12. Composite

MediumStructural1 hidden requirement

Treating a leaf and a container through one interface, so nesting costs nothing

Explorer adds up everything under a node, and the tests pass on the tree it is given.

It walks the tree itself, with a loop for the folder and a loop for the folders inside it. Two levels, hand-written — so three levels needs a third loop, and four needs a fourth.

Node declares size(), and Folder already implements it by asking its children. Rewrite totalSize() so depth stops being its problem.

This is not Open/Closed with different names. No new kind of node arrives; the tree just gets deeper.

Run compiles every file and runs Tests.java — the tests you can read.

Submit runs those again, then applies 1 requirement you have not seen, one at a time.

Your code is never edited. Each requirement is added to the project as it stands. If the design is right, nothing you wrote has to change.

  • Ctrl/⌘ + Enter runs the tests