Tuesday, July 22

What is a class?

When I interview a candidate for a software developer position I often start simple; a question like "what is a class?" Often I get a perfunctory and incomplete answer like "functions and variables" and "a way to make objects" (sometimes they are much worse... way off the mark.) A few days later I will hear that the candidate wasn't happy that I asked such an "academic" question.

I don't want an academic answer. I want what I so rarely get... passion, interest, the beginner's mind, the journeyman's skill, a desire to explain, a mention of encapsulation or inheritance. I'm looking for an intelligent answer.

To myself I would answer something like this... "what underlies a class in object-oriented programming is the need to manage complexity through the classification of objects, both concrete and abstract. The class serves as a template for instantiating objects with distinguishing characteristics, represented as attributes and methods. The object's state is controlled by the object's attributes defined in the class. The object's behaviors are invoked through the methods defined in the class. In this way the class encapsulates data and functions together in a coherent way that can represent specific entities, elements of structure, events to remember, roles, etc. Classes provide structure and organization to the program with general-specific and whole-part relationships. A classes is the DNA, if you will, of the microorganisms that inhabit the larger software ecosystem."

By way of example, "I look at the objects around me and see how every Honda Civic is an instance of the same class with attributes like color, model, mileage and VIN number distinguishing each instance. When I want to pop the hood of another Civic the method is routine and familiar. My car is an instance of the specific Civic class. In turn, the Civic is a specific Car which is a specific of the generalization Vehicle. The Vehicle class has the attributes and methods that allow for things like vehicle license and registration and resale. The whole car is composed of parts, which are themselves instances of a classes. My insurance policy, a speeding ticket, a gasoline receipt are all class instances in some other structure of things-to-be-remembered. Every object instance has attributes and behaviors that are intrinsic to that class that allow for classification and structure."

This is the kind of answer I'm really looking for.

No comments: