In this article, we will discuss the key concepts important to Object Oriented Programming (OOP). An object-oriented system has the following characteristics
· Inheritance
· Polymorphism
· Abstraction
· Encapsulation
· Decoupling
Some systems (and some languages) don’t fully support all the above constructs and still refer to themselves as “object-oriented”. This is a matter of some debate, but it is my opinion that a language or system must implement each of the above concepts in some way in order to be considered object oriented.
Inheritance
Inheritance is the ability to create a class based on an existing class. In this model, the existing class is known as the “parent class”, or “base class” and the new class is known as the “child class” or “derived class”. By default, a child class will inherit all properties and methods of its parent class.
Marking a method as virtual in a parent class allows it to be overridden in a child class. This means that the method can be replaced in the child class with new code.
It is possible to have multiple child classes that inherit from the same parent class. In some languages, it is also possible for a child class to inherit from multiple parent classes.
Sometimes I find myself writing a lot of conditional logic in the methods of a class. For example, I may want the object’s method to perform one set of actions under some specific circumstances; under other circumstances, I expect it to behave differently. When this happens, it is a good time to consider refactoring my class into two related classes, each of which inherits from a common base class. The base class contains code relevant to both subclasses, while each subclass class contains only code specific to its own needs.
Interface Inheritance
Inheriting from an interface is similar to inheriting from a class, except the parent class does not contain any implementation, so each subclass must provide all the code for all the methods defined in the interface. This is useful if a set of subclasses need to share the same public members but do not have any code in common. In most object-oriented languages, Interfaces also have the advantage that a single class can inherit from more than one interface.
Polymorphism
Earlier, we said that objects communicate by passing messages via their public interface.
Polymorphism is the ability for different objects to respond to the same messages in a different - but appropriate - way. In OOP, this is done using inheritance. Because a child class inherits properties, fields and methods from a parent class, we can have several different child classes sharing the same public members. Each of these classes would therefore accept the same message types. However, each derived class may override some of the behavior of the base class and may do so in a way appropriate to itself.
For example, we may create a Vehicle class that has a method Drive() that accepts no parameters.
We can derive two child classes - Car and Airplane - from Vehicle and they will each inherit the Drive method. But driving a car is not like driving an airplane, so each of these methods would be overridden and the overridden child methods would be very different from one another. Calling the Car’s Drive method would cause the axels to turn and rotate the four wheels beneath the car. Calling the Airplane’s Drive method would explode jet fuel and propel the airplane through the sky at a high velocity.
This is an example of two objects (Car and Airplane) that accept the same message (Drive) and respond differently but appropriately.
The picture below shows the hierarchy of classes that inherit from a single parent class.

Abstraction
Abstraction is the process of simplifying an object or system by focusing only on those parts of the system relevant to the current problem. In OOP, abstraction is typically implemented using encapsulation.
Encapsulation
Encapsulation hides implementation details of an object from that outside world. Again, this goes back to our goal of decreasing complexity. We don’t need to understand all the workings of an object in order to use it. Returning to our Automobile example, in order to start a car, I need only know to put the key into the ignition and turn it for a short time. A lot happens inside the car (gasoline is injected, battery is engaged, sparks fly, gas explodes) but I don’t need to the details of any of that in order to start the car. In fact, it’s easier for me to focus on starting the car if I ignore the other things going on within the automobile.
Decoupling
Finally, decoupling is a key point of object oriented programming that simplifies a system. In a decoupled system, the dependencies between objects are minimized. Encapsulation helps with this because external objects cannot change the internal attributes of an object if they cannot access it.
However, the responsibility for decoupling ultimately rests with the developer. Use messages to communicate between objects and maintain as little state as possible. Expose only those attributes needed by others and avoid coding side effects in your object’s methods.
In my experience, decoupling is the OOP concept that is ignored the most by people trying to build object oriented systems.
Summary
In this article, we described the advantages of Object Oriented Program; the basics of working with classes and objects; and the fundamental concepts that mAbake up OOP.
As we stated at the beginning of this article, the goal of Object Oriented Programming is to manage complexity. We do this by modeling our application as many people see their real world systems – as a set of loosely coupled objects that interact with one another. This helps us to split a complex problem into a number of more manageable objects. It also allows us to simplify the management of those objects by encapsulating complexity, maximizing flexibility through inheritance, and keeping the objects independent of one another.
David Giard has been developing solutions using Microsoft technologies since 1993. In the past, he has spoken at Day of .Net, CodeStock, Microsoft DevCares, Microsoft ArcReady, Dot Net University, X Conference and numerous user groups around the Midwest. He is a recovering certification addict and holds an MCTS, MCSD, MCSE, and MCDBA, as well as a BS and an MBA. He is the host and producer of the popular online TV show Technology and Friends. He is an officer of the Great Lakes Area .Net User Group. He is an avid photographer and has visually documented many of the Heartland community events. You can read his latest thoughts at www.DavidGiard.com. David lives in Michigan with his two teenage sons.