Add a child to a tea
transcript
Quick question. Can you add a child to a cup of tea? The answer depends on where you put the add method.
Safe: only the group has an add method. A tea has no add method at all. Transparent: every node has add. So a tea has to say no.
In Java and C plus plus, adding to the tea won't even compile. The mistake is caught before you run. Adding to a group is fine, of course. But here's the catch. Code that holds only the shared interface can't add to anything.
Now every node has add. Code treats them all alike, group or leaf. The tea refuses. But only when the code runs. Not before. The book emphasises transparency. Java's AWT toolkit is the safe kind. The browser's DOM is the transparent kind.
Early errors, or one uniform interface. Pick one, on purpose. And say why.
Full breakdown in the lecture.