LINUX FOR YOU
C M YK
bject-orientedprogFramming (OOP)has been the mostpopular programmingparadigm for more thantwo decades and has been thesubject of active research for quitesome time now.With such widespread use, wewould expect the essence or basictenets of OOP to be widely knownto students and practitioners.However, the essentials are notoften understood or followed well inpractice. By just programming in anobject-oriented language does notnecessarily mean that we do thattask well. In this article we will lookat the fundamentals of objectorientation and try to understandwhy it has become so successful.We’ll also dispel some myths andface some hard facts about OOPtechnology.
What is object-orientedprogramming? HanspeterMossenbock’s
Object-Oriented Programming in Oberon-2
[Springer-Verlag, 1993] provides thefollowing definition: “Object-oriented programming meansprogramming with abstract datatypes (classes) using inheritanceand dynamic binding.” This makes itclear that OOP is about using ADTswith inheritance and virtualfunctions.Many of the attributes weoften associate with OOP aren’tinherently associated with thisdefinition. Strictly speaking,having a common base class (say,the object class), or languagefeatures like namespaces,exception handling, RTTI (RunTimeType Identification), reflection,operator overloading, functionoverloading, etc, are nothing to dowith OOP, as such. However, manymodern OOP languages (like Java)have a lot of these features, whichdoesn’t mean they arecharacteristics of object orientationitself. A language can have none of these features and still can beconsidered as a good OO language.
An example of flawedarguments
I recently heard the followingargument: “Java is better than C++because Java is a ‘pure’ object-oriented language. Java allows noglobal variables, it has a commonObject base class, and it does notsupport multiple inheritance and soon. But C++ is a bad object-orientedlanguage because it supportsprocedural programs, has nocommon base class, supportsmultiple inheritance, etc.”I like both Java and C++, butthat aside, let us analyse why thisargument is inherently flawed.Just because we believe that Javais a ‘pure’ OO language, it need notbe better than C++. Why is ‘pure’object-orientation better than anyother approach (like the multi-paradigm approach in C++)? Whatare the criteria for concludingwhether a language is ‘pure’ or‘impure’? Doesn’t Java’s supportof C-style conditional and loopingconstructs, and primitive typesmake it ‘impure’? Just because alanguage also supports otherparadigms doesn’t mean that it is abad OO language.Providing a common base class isa design decision that a languagedesigner makes in an OO language.Based on information and categorytheories, many researchers havesupported the argument that havinga common class as a base class for allthe classes is unnatural and a non-intuitive design.Inheritance is one of thefundamental features of OOP. Alanguage without any form of inheritance support cannot claim tobe an OOP language. Multipleinheritance is just one kind of inheritance and it is common to seeit in use (for example, a two-in-oneset inherits the properties of both atape-recorder and a radio).Practically, it is difficult to usemultiple inheritance correctly, and
the problems that may needmultiple inheritance can berewritten using only singleinheritance (possibly with somedifficulty). Because of suchreasons, a language designer canmake a design decision to supportor not support multiple inheritancein her language. However, justbecause an OO language supportsmultiple inheritance we cannotlabel it as a ‘bad’ language. As Paul Weiss wiselycommented: “It’s one thing not tosee the forest for the trees, butthen to go on to deny the reality of the forest is a more seriousmatter.”
Characteristics and benefits
OOP is based on the solidfoundation provided by theconcepts of inheritance,polymorphism, abstraction andencapsulation. An abstract data type providesus with the ability to think of atype in its abstract interface leveland use it depending on itsinterface only (without concerningourselves with the implementationdetails; otherwise, there is nothing‘abstract’ about an ADT). SinceOOP is based on the solidfoundation provided byabstraction, it is possible to createcomplex software that hides a lotof implementation details. Becauseof this, object orientation issuitable for programming on alarge scale.Inheritance is the mechanismin which common properties of various classes (or objects, in caseof object inheritance) areabstracted and provided incommon base classes, therebycreating relationships betweenrelated types. Inheritance isimportant for design since it helpsto organise classes in terms of thenatural relationship between thetypes. In inheritance many of thedetails of the derived classes willonly be known later in the designstage. Also, because of the