What is Object-Oriented Programming?
What is Object-Oriented Programming?
To understand object-oriented programming, let me first give you a little bit of OOP theory. What is the purpose of a computer program? Quite simply, a program tries to solve a real-world problem using computers. To do this, OOP says that we need to create a model of the real world in the computer’s digital world.
In the real world, things interact with other things. For “thing”, think of people, animals, places, objects—any noun. The OOP model of a real-world thing is called an object. Things have features that describe them, and separate them from other similar things. Thus objects have data that describes what they’re like, and unique names that distinguish them from other similar objects. Things do stuff, both to themselves and to other things. Likewise objects have methods that operate on themselves or on other objects.
The concept of objects isn’t new; before OOP came around, there have been various programming structures that use objects as models of the real world. What sets OOP apart is its fundamental focus on objects in trying to solve the two problems that I described earlier. To address the complexity of software systems, OOP developers create objects that encapsulate data and functions in abstract modules. To address the need to reuse software, OOP developers design objects to allow them easily share their behavior with other objects. These features of objects in OOP bring us to our definitions:
You probably don’t understand what all this means just yet, but you will soon. First, let me introduce you to a few popular object-oriented programming languages.
Some Major Object-Oriented Programming Languages
- Smalltalk: Many object-oriented programming languages (OOPLs) have been developed over the years. Smalltalk, developed around 1980, was one of the earliest modern OOPLs. It is a pure OOPL designed to make graphical programming easier (Sutherland 1995). OOP “purity” is beyond what I can discuss in detail in this primer, but I can simply say that in a pure OOPL, everything is an object—everything from the computer that runs the program down to the lines of code that the programmer types. For those who worship OOP as their religion, pure OOPLs like Smalltalk are the faith of the undefiled.
- C++: Up till recently, C++ has been the most popular OOPL. It inherited a lot of its popularity from the beloved C language, using its basic syntax and extending its features. C++ has been called “a better C” (Schildt), but to relegate it to the status of a mere “C 2.0” ignores the radical changes that object-orientation permits. Unfortunately, its backward compatibility with C means that it is easy to use new C++ features to write non-OOP code, even using OOP features. This is why OOP purists stay away from C++ like a Jew shuns pork.
However, because of its ability to straddle the old and new ways of programming, I will use C++ for my programming examples. Hopefully the fundamental difference between OOP and the traditional way will become clear when I use the same language to do both.
- Java: Developed by Sun Microsystems in the early 1990s (Naughton), Java has recently taken the OOP scene by storm. It is very nearly a pure OOPL, close enough at least that the purists don’t feel they’re compromising their principles as they flock to it. Taking its time to get to the party, Java has been able to synthesize many of the best features of OOPLs. If you’re looking for an OOPL to learn, I personally recommend you brew a pot of dark roast Java.
Now that you have a general idea what OOP is and you know some popular OOPLs, I will explain in greater detail what objects and OOP are about. I will do this by describing how OOP uses objects to address software complexity and the need to reuse.