Friday, March 14, 2003

Experience Mathematics #29 -- Abstraction

The first time you encountered abstraction in mathematics was when you associated the number (say $5$) with five oranges and five apples. When we begin to learn mathematics, we associate numbers with specific objects. Soon we realize that we can think of the number $5$ as a concept removed from the apples and oranges. This is abstraction. Now we can apply the concept of $5$ (and also other numbers) in counting any set of objects.

Mathematics students become used to abstracting concepts into symbols that we can apply in many situations. The same skill in abstract thought helps in other domains also. For example, object oriented programming—the most useful of the programming paradigms is all about abstraction.

In Object-oriented programming, we think of everything as an object. For example, the button you press in most applications is an object. Now a button looks and behaves in much the same way in any application. So we would naturally wish to program it just once. So most language environments (like Java or Visual Basic) give us a “Class” that represents the object that is the button. (A Class is like the set we encounter in mathematics.)

However, when we use the button in a particular program, we may wish to add certain properties of our own. For example, we may like to put the word “OK” as a label on the button we wish to use. So we “instantiate” a button and set its properties that include a label “OK” that will appear on it. Further, when a user clicks on the button, the button performs an “Action”. You have to code this “Event” to tell the button what to do.

The Classes contain data (or “properties”) that are used to describe a particular member (or “instance”) of the class, functions (or “methods”) that do certain tasks, and have the ability to process messages (or “events”) that the rest of the application uses to tell the class to perform its tasks.

No comments: