We are information workers and the stuff we create is mostly intangible. The structures and models that underpin our code are abstract. Most of us need to concentrate while coding because it takes concentration to hold the models in mind while we tinker with them. Almost all of the work done at “enterprisey” companies uses an object-oriented language like Java or C#.
So I’m always surprised when an experienced C# or Java programmer has no mental model or concept of what a “class” or “object” is. These object-oriented programmers, what have they been declaring and instantiating all these years?
I’m not making this up.
Eight years ago I was nearly too embarrassed to even think of asking such a dopey question of supposedly experienced programmers, I mean it’s like asking if they’ve ever used a computer, right?
Many interviews later I confirm that most programmers are glad of such a simple warm-up question, it breaks the ice and helps get some kind of conversational flow going. The programmers who know their stuff actually like talking about the basics, it’s like a shared culture.
But others… I might as well ask how neutrinos could possibly travel faster than light.
“A class and an object? They are exactly the same!”
“A class is like a car, an object is like an animal”
After a run of two or three interviews like this I sometimes wonder if I’m being overly theoretical (ha!) but it takes just one interview with a competent programmer and I know the bar is in no way set too high.
So for the record, what is the right answer?
Here’s what the textbook says:
“A class is a set of objects that share a common structure and a common behaviour. An object is an instance of a class…”
— Grady Booch
Here’s the wisdom of the masses:
“…a class is a construct that is used as a blueprint to create instances of itself – referred to as […] objects…”
WHY DOES IT MATTER?
Give a man some fire, and he’ll be warm for a day. Set a man on fire, and he’ll be warm for the rest of his life, or something like that.
I’m sure you get the idea. A person who understands the fundamental concepts of their profession has a solid base for learning everything else.
A person who gets by with memorising tricks will be stuck when code pasted from somewhere fails to work, or when a job requires original thought.