Back to the Lobby



OOPgeneral

So, What Is Object -Oriented Programming?

Before embarking on a historical and cultural analysis of object-oriented programming, we will define some of the terminology that will be used in the discussion. Object-oriented programming is defined as a new programming paradigm that functions by d efining a set of object classes and the methods defined on those classes. The chief difference between OOP and the imperative or functional paradigms is best defined as a difference of responsibility. Whereas in imperative programming languages the prog rammer has to specify what the program needs to do in every contingency, in OOP each object is "responsible" for its own behavior via a set of methods defined on it that cause it to react to messages that other portions of the program may send it.

I would like to use a brief example suggested by the Stanford Computer Science Lecturer Nick Parlante to illustrate this difference. Let us imagine a large party with CS undergraduates, graduates, and lecturers present. As the party is coming to an end, the host orders the crowd to disband. In an imperative-programming language, this would necessitate the programmer to step through all of the different people present (probably by using a loop), determine where the home is for each one of them, and devise the proper routine for sending those people home. If a host had to operate under this model, it would probably take him until sunrise to send each of his guests to their destinations. In an OOP program, on the other hand, each guest would know o n their own how to respond to the host's yell "Go Home!", and would automatically respond appropriately after hearing this. Each guest may repond in a different manner: for example, undergraduates don’t have cars, so unlike the lecturers, they would ge t on their bikes to get home, while the graduates don’t have homes at all, and would go to sleep on the floor of the computer laboratory in the basement of Gates. The key point is that the host-programmer’s job is made much easier, because each object-g uest is responsible for obeying the disband instruction.

This behavior is accomplished by having each object be an instance of a particular class. Each class has a set of methods and a set of internal variables. These methods and variables combine to define the behavior and state of the class. Classes can have different entirely different methods and variables. At the same time, some methods may exist for several classes, although each class would define them differently. In that case, it is up to the compiler to determine at run-time the class of an ob ject and use the appropriate method for it. This behavior is referred to as polymorphism. When the programmer wants an object to do something, the programmer sends that object a message, which in turn calls on one of the object’s methods to execute itse lf.

Another useful feature of object-oriented programming is inheritance. If two classes exhibit very similar behavior, with only a few minor differences, it is possible to factor the common behavior into a common superclass, and create two subclasses of it. The subclasses would generally respond to the messages from their superclass, but would override or add messages when their behavior differs from that of their superclass.

Inheritance is particularly important because it is the central mechanism behind the extensive libraries in most OOP languages, such as Smalltalk. These libraries allow programmers to use already written classes for such common tasks as drawing menus or creating dialog boxes. Programmers can make their own classes which inherit most of the behavior from the existent superclasses, and override only a couple of methods for those cases in which they want a different behavior.

The OO paradigm reduces the interdependency among various software components and allows programmers to develop libraries of reusable classes. The components can be created and tested separately and integrated in later stages, increasing the possibili ties for parallel programming and, therefore, making programmers more efficient.

The lack of any specific references to concrete languages in the above discussion once again highlights the essential difference between the OO languages and the OO paradigm. [See: How OOP Programmers Think]. The paradigm itself models a general appro ach for programming and is, essentially, independent of a language base. Please see the next section for a description of the implementation of OOP in Smalltalk.

References:

Timothy Budd, An Introduction to Object-Oriented Programming, Addison-Wesley, 1997

Nick Parlante, CS108 lectures, Stanford, CA, 1998

Personal experience in OOP Programming




For additional information about OOP:
What is OO Software?