You are on page 1of 3

Insight

Insight

On the Notion of
Object-Oriented
Programming
This article discusses the fundamentals of object orientation, and in the process dispels
some myths about it.

98 JANUARY 2008 | LINUX FOR YOU | www.linuxforu.com

CMYK
Insight

bject-oriented these features and still can be the problems that may need

O progFramming (OOP)
has been the most
popular programming
paradigm for more than
two decades and has been the
subject of active research for quite
considered as a good OO language.

An example of flawed
arguments
I recently heard the following
argument: “Java is better than C++
multiple inheritance can be
rewritten using only single
inheritance (possibly with some
difficulty). Because of such
reasons, a language designer can
make a design decision to support
some time now. because Java is a ‘pure’ object- or not support multiple inheritance
With such widespread use, we oriented language. Java allows no in her language. However, just
would expect the essence or basic global variables, it has a common because an OO language supports
tenets of OOP to be widely known Object base class, and it does not multiple inheritance we cannot
to students and practitioners. support multiple inheritance and so label it as a ‘bad’ language.
However, the essentials are not on. But C++ is a bad object-oriented As Paul Weiss wisely
often understood or followed well in language because it supports commented: “It’s one thing not to
practice. By just programming in an procedural programs, has no see the forest for the trees, but
object-oriented language does not common base class, supports then to go on to deny the reality of
necessarily mean that we do that multiple inheritance, etc.” the forest is a more serious
task well. In this article we will look I like both Java and C++, but matter.”
at the fundamentals of object that aside, let us analyse why this
orientation and try to understand argument is inherently flawed. Characteristics and benefits
why it has become so successful. Just because we believe that Java OOP is based on the solid
We’ll also dispel some myths and is a ‘pure’ OO language, it need not foundation provided by the
face some hard facts about OOP be better than C++. Why is ‘pure’ concepts of inheritance,
technology. object-orientation better than any polymorphism, abstraction and
other approach (like the multi- encapsulation.
The basics paradigm approach in C++)? What An abstract data type provides
What is object-oriented are the criteria for concluding us with the ability to think of a
programming? Hanspeter whether a language is ‘pure’ or type in its abstract interface level
Mossenbock’s Object-Oriented ‘impure’? Doesn’t Java’s support and use it depending on its
Programming in Oberon-2 of C-style conditional and looping interface only (without concerning
[Springer-Verlag, 1993] provides the constructs, and primitive types ourselves with the implementation
following definition: “Object- make it ‘impure’? Just because a details; otherwise, there is nothing
oriented programming means language also supports other ‘abstract’ about an ADT). Since
programming with abstract data paradigms doesn’t mean that it is a OOP is based on the solid
types (classes) using inheritance bad OO language. foundation provided by
and dynamic binding.” This makes it Providing a common base class is abstraction, it is possible to create
clear that OOP is about using ADTs a design decision that a language complex software that hides a lot
with inheritance and virtual designer makes in an OO language. of implementation details. Because
functions. Based on information and category of this, object orientation is
Many of the attributes we theories, many researchers have suitable for programming on a
often associate with OOP aren’t supported the argument that having large scale.
inherently associated with this a common class as a base class for all Inheritance is the mechanism
definition. Strictly speaking, the classes is unnatural and a non- in which common properties of
having a common base class (say, intuitive design. various classes (or objects, in case
the object class), or language Inheritance is one of the of object inheritance) are
features like namespaces, fundamental features of OOP. A abstracted and provided in
exception handling, RTTI (RunTime language without any form of common base classes, thereby
Type Identification), reflection, inheritance support cannot claim to creating relationships between
operator overloading, function be an OOP language. Multiple related types. Inheritance is
overloading, etc, are nothing to do inheritance is just one kind of important for design since it helps
with OOP, as such. However, many inheritance and it is common to see to organise classes in terms of the
modern OOP languages (like Java) it in use (for example, a two-in-one natural relationship between the
have a lot of these features, which set inherits the properties of both a types. In inheritance many of the
doesn’t mean they are tape-recorder and a radio). details of the derived classes will
characteristics of object orientation Practically, it is difficult to use only be known later in the design
itself. A language can have none of multiple inheritance correctly, and stage. Also, because of the

www.linuxforu.com | LINUX FOR YOU | JANUARY 2008 99

CMYK
Insight

classification of related types, we background, it takes more time With OOP we can write
can write code for general types to learn the object-oriented generic, reusable components
(instead of code that works or approach than to learn the and sell it independently.
assumes specific types). This gives language features.
rise to runtime polymorphism where Object-oriented programs are Partially true! One of the
late binding of actual methods for typically more difficult to understand fundamental benefits with OOP is
the code is resolved. With than their procedural equivalent. the ability to write reusable code,
inheritance (and runtime For example, to understand how but OOP hasn’t delivered fully in the
polymorphism), it is easier to to use a derived class, we need to go writing and distributing of generic
introduce new changes and extend through the public members of that reusable code, in practice. Writing
the software with new types without class and also the public members COTS (Components Off The Shelf)
affecting the rest of the code, so of all of its base classes. The effort software is still not fully possible
OOP programming required to understand and make with OOP. The emerging areas of
enables writing extensible software. use of class libraries, frameworks component software and generic
Object orientation also enables or inheritance hierarchies is programming paradigms address
providing abstract or concrete considerable. this shortcoming of OOP.
classes as libraries and related Object orientation provides a
classes as frameworks; instead of higher level of abstraction from OOP emerged based on solid
(re)writing classes every time, low-level details and it provides theoretical foundations.
we can reuse the classes. So features to model higher-level
object orientation helps writing relationships between classes. This False! Unlike programming
reusable software. flexibility also comes with some paradigms like functional
So the ability to handle complex loss of efficiency compared to programming, which is based on
code (enhanced maintainability), straightforward procedural lambda calculus and emerged from
the ability to extend the code constructs. For example, to extensive academic research,
based on specific requirements support runtime polymorphism, an object orientation came into
later (extensibility) and the ability extra level of indirection is needed practical use first and was later
to use or reuse the code to invoke a virtual method. In other subjected to extensive research.
(reusability) are the main benefits words, a virtual method call is Theoretical understanding of
promised by OOP. almost always slower than a direct many of the areas on OOP is still
method call. Such additional hazy and OOP continues to be a
Costs and drawbacks overhead for abstracting low-level subject of active research.
OOP is not a panacea for the details is known as an abstraction
problems faced by the software penalty in OOP. It takes time to master
industry today. With more than object-oriented programming
three decades of experience in Some myths and realities and design.
using object-oriented programs, the We will encounter many myths
hype and over-enthusiasm in associated with OOP. Let us check True! It is easy to understand
promoting object orientation has the validity of some of them here. the basic tenets, features and ideas
subsided and the costs of object- of OOP. However, it takes
oriented programming are clear. Software written in OOP is considerable time to master the
Object orientation requires a better than non-OOP software. analysis, design and implementation
new way of thinking (different from techniques to create quality
procedural thinking), and it is False! While it is true that OOP solutions using object-oriented
difficult to comprehend object- provides significant help in creating technology. As they say, nothing
oriented programs. Since object quality software, the quality of the good ever comes easy!
orientation provides a higher level software we create is in our hands, and
of abstraction from machine-level good or bad software has nothing to do
By: S.G. Ganesh is a research
details, there is some loss of with OOP. We can write high-quality
engineer in Siemens (Corporate
efficiency (compared to procedural code in other programming paradigms
Technology). His latest book is “60
programs). (like functional programming);
Tips for Object Oriented
The benefits of OOP aren’t similarly, we can also write sloppy
Programming”, published by Tata-
automatically available to programs code following OO approach. So, it is
McGraw Hill in December this year.
written in the procedural way— incorrect to make claims like: “My
You can reach him at
by just using OOP constructs. software is better than your’s because
sgganesh@gmail.com
For programmers with a procedural mine is OO whereas yours isn’t!”

100 JANUARY 2008 | LINUX FOR YOU | www.linuxforu.com

CMYK

You might also like