Hacker News new | ask | show | jobs
by aleprok 4888 days ago
The lunch line is awesome example of real world programming concepts.

Myself I have taught few people how to understand object orientation like this. Though my example is not good for kids, but older people.

Told them to think about a beer can and asked them what kind of properties they have. Amount of beer in it, the color of the can, the material of the can, the labels and icons. After they realize these properties I have explained them that how they could code these as class variables.

If they understood that I asked them what kind of functionality beer can has. They have answered, opening it and drinking from it. I told them these are the two functions for the class. The opening of beer can is void method with no parameters and drinking from it is a method with parameter and possibly with a return value.

If they understood that I could go into the relationship of beer can and beer crate.