On classes and objects

Hi, friends!

In a job interview as a junior software developer, I once was asked to explain the difference between classes and objects. Of course, if you are a developer that question is no challenge at all, but actually there are people leaving university with a computer science related degree who have never understand object oriented programming, so I guess the question makes sense to filter out candidates on a very basic level.

When asked, I looked around, pointed at a chair and replied: ” ‘Chair’ is a class, and this specific chair over there is an object and an instance of the class ‘Chair’. The class defines what a chair is…” The answer was good enough to proof that I understood the concept of classes and objects and was therefore accepted, but I have to admit that it’s not the best example to explain classes and objects to somebody who doesn’t get it yet.

Yesterday I realized that there is a pretty obvious example that at least every Gamer will understand immediately (and most IT people have played some games in there life, right?):
“In a game there may be classes like ‘sorcerer’ and ‘fighter’ and ‘rogue’. And then there is your player character, who may be an instance of the class ‘fighter’. The class defines the game rules for all the fighters in the game, for example that fighters have hit points and an attack value. Your player character is only one object, holding the individual values in these properties like 500 hit points, while other fighters in the game may have different values.”
I like this example so much, because this example for classes are actually called classes in the games.

I don’t expect to be asked this question ever again, since I don’T apply for junior positions any more. It’s a pitty, I would love the fact that I talk about sorcerers and fighters in a job interview…

Leave a comment

Your email address will not be published.