Count says two
transcript
A food app menu. It shows four items on screen. But the count says two. Nothing crashed. Nothing was logged. So where did two items go?
Count walks the Wraps category. First, the paneer wrap. One. Next, the egg wrap. One. Then the combo. It has two items inside it. Count says zero. Total: two. And two looks like a perfectly valid answer.
Here's the count function. It has a branch for items. And one for categories. But the combo branch was never written. So it falls to the last line: return zero. Three functions, three kinds of node. Nine branches needed. Only eight written.
The fix is Composite. The caller asks one interface, and only one question: count. An item answers one. A group asks its children and sums the answers, whatever they are. No kind to check. So no branch to forget, ever.
A new kind of node answers for itself. Nothing else is edited. Not one function.
Full breakdown in the lecture.