Sunday, November 13, 2005

The Principle of Subsumption

Explain the principle of Subsumption, also known as the Liskov Substituiton Principle.

From Joshua Bloch and Neal Gafter's Java Puzzlers book:

This principle says that everything you can do with a base class, you can also do with a derived class. Subsumption is an integral part of the natural mental model of object-oriented programming. Whenever it is violated, a programm becomes more difficult to understand.

Measure time with two ropes and some matches

Imagine you have two ropes of different sizes. Both ropes are not of consistent thickness, i.e. each rope can be at one point thick and at another one very thin. All you know is, that each rope takes exactly one hour to burn completely.

How can you measure exactly 45 minutes by burning the ropes and without any other tool to be used than a match?

Java String Class

Assume there is no String class in Java. Implement one and optimize it. How would you do it?