Square is not Rectangle ...Wait What?

The student had already finished the daily code review and was looking forward to newer challenging exercises. He had finished a Red Bull and Gatorade. The master was nowhere to be found. The lunch orders were to be made. The student wasn't hungry nor was he thirsty. He secluded himself to the room with the bean bags. It was where he meditated about the inner workings of soul, body and MacBooks. It was exactly  at this time that the voice of the master was heard from the main dojo.

Master called all novices and asked them to work on a new kata. He asked them to build a rectangle class with methods area and perimeter. Further, he asked them to build a square class with methods area and perimeter. Students were grouped and then asked to proceed to the task.

Implementations were widely different from what where expected. Some had created two different classes. Some had gone for inheritance. Some had gone for overridden inheritance. Some were still implementing even when the time limit was over. The master was pleased with the implementations, but his face never showed it.

Master started to disprove each and every implementation. The first, of course, was one where there were two classes and nothing was shared between them. Master asked them about why area and perimeter were not inherited or at least derived from rectangle class. The answer was not easy and novices kept mumbling amidst themselves. Next was the one where implementation was based on  overriding the inherited methods. There was nothing to disprove here as they themselves agreed to their mistake. The third one was where the initialization had been overridden and the rest were inherited. Master had only one thing to say

A square is not a rectangle.

The student was perplexed with this ambiguous statement. His katana slid away from his hand. The other groups also started murmuring within themselves. Master had only one more thing to say.

Written on July 14, 2015