Abstraction: The Model for Modeling

Object-Oriented Programming strongly emphasizes abstraction, perhaps I can go as far as to say it’s the true core of the OO paradigm.

OO tries to model reality, or rather, it tries to model our perception of reality. What amazes me most about our perception is abstraction. We look in one direction, and our brain applies its amazingly complex pattern recognition to tell “us” what it is we see. If we look towards a tree then surely we will recognize it as a tree as well. But is it really a tree? On might reasonably argument that calling it a tree omits too much detail, and they might go on to say that providing only this information would be close to useless. What about the size, the color, the age of the tree? These could all be important properties and could potentially be modeled into a tree object in a computer program. The idealist could go even further and ask about the number of leaves the tree has, he might ask for the weight in milligrams rather than kilograms. What about the number of atoms the tree consists of?

Surely a more accurate version of the tree would be depicted if every atom was numbered, but would it be in any way helpful to us? What we gain in detail will prevent us from looking at any tree other than the our original exemplar. In how many atoms may an object differ from our tree and still be a “tree”? Without thinking about it our mind makes it perfectly clear what is a tree and what isn’t. We have abstracted reality into bigger pieces, and unless we really want to dig into the details of our objects (for instance, to count the amount of leaves of our tree) we don’t have to.

I worked with OOP without thinking too much about what a great concept this abstraction is. It amazes me how powerful it is, and it amazes me even more that we can use it without ever thinking about what it really is. What is an ArrayList? I know its ADT definition, but how does it really function internally? Sure, I know the basics such that it has an aggregate array which it may replace when objects are added or removed to simulate that the ArrayList can have an arbitrary size (or is it really implemented in this way in a given language implementation? I don’t know, but this only helps in making my point.) but this is also an abstraction. I have never checked the source of an of any ArrayList implementation to see all the odds and ends of the it, and even if I had, what would the machine code look like?

Another amazing part of abstraction is one that i briefly touched a little earlier in this document. Our prototypical tree could not help us to distinguish other trees if our abstraction level was the prototype’s atoms and their locations. All this information is overwhelming and we cannot possibly make sense of it. So we turn to our abstraction, the “tree” and immediately we can distinguish leaves, branchen, roots and its trunk. We can see these characteristics in other objects and conclude whether it’s likely that they are also trees. Somehow providing us with less accurate information is so much more useful!

Consider Java programs. Java runs on a virtual machine called the JVM. The JVM is available for a large number of systems, but it’s more accurate to say that there are a large number of JVM’s available, each able to run on its designated system. This means that our high-level language gave us the opportunity to write programs for several different systems just as easily as writing them for one system only! To me it seems almost paradoxical that this works out to be as beautiful as it is. But it also seems to be the same thing as our “tree prototype” that lets us identify different trees. Or is it the same? I haven’t thought enough about it to be sure yet.

For a wonderful look at abstraction, both in the real world and in computer sience, see Douglas R. Hofstadter’s excellent book Gödel, Escher, Basch: An Eternal Golden Braid. Also see Structure and Interpretation of Computer Programs for to among other things learn how different levels of abstraction and their clear separation is helpful. Also available are the authors’ video lectures.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options