Features and benefits of OOP
Having become acquainted with the terminology of OOP,
we will briefly review what are generally considered features
and benefits from a pragmatic point of view.
This summary is based on [Pok89].
I do expect, however, that the reader will take the necessary caution
with respect to these claims.
See slide [1-features].
Both information hiding and data abstraction
relieve the task of the programmer using existing code,
since these mechanisms mean that the programmer's
attention is no longer distracted
by irrelevant implementation details.
On the other hand, the developer of the code (i.e. objects)
may profit from information hiding as well
since it gives the programmer the freedom to optimize
the implementation without interfering with the client code.
Sealing off the object's implementation by means of a well-defined
message interface moreover offers the opportunity
to endow an object with (possibly concurrent)
autonomous behavior.
Features of OOP
- information hiding:
- state, autonomous behavior
- data abstraction:
- emphasis on what rather than how
- dynamic binding:
- binding at runtime, polymorphism \nop{, virtual functions}
- inheritance:
- incremental changes (specialization), reusability
slide: Features of OOP
The flexible dispatching behavior of objects that lends objects
their polymorphic behavior is due to the
dynamic binding of methods to messages.
For the language C++, polymorphic
object behavior is effected by using virtual functions,
for which, in contrast to ordinary functions, the binding to
an actual function takes place at runtime and not at compile-time.
In this way, inheritance provides a flexible mechanism by which to reuse code
since a derived class may specialize or override
parts of the inherited specification.
Apparently, at the current stage of OOP, it is still difficult
to distinguish clearly between what are just features and what
must be regarded as actual benefits.
From a pragmatic viewpoint, OOP offers encapsulation
and inheritance as the major abstraction mechanisms to be used
in program development.
See slide [1-benefits].
Encapsulation promotes modularity, meaning that objects must
be regarded as the building blocks of a complex system.
Once a proper modularization has been achieved, the implementor of
the object may postpone any final decisions concerning the implementation
at will.
This feature allows for quick prototyping, with the risk
that the `quick and dirty' implementations will never be cleaned up.
However, experience with constructing object-oriented libraries
has shown that the modularization achieved with objects
may not be very stable. See chapter 11.
Another advantage of an object oriented approach,
often considered as the main advantage, is the reuse of code.
Inheritance is an invaluable mechanism in this respect,
since the code that is reused seldom offers all that is needed.
The inheritance mechanism enables the programmer to
modify the behavior of a class of objects
without requiring access to the source code.
Benefits of OOP
- OOP = encapsulation + inheritance
- modularity --
autonomous entities, cooperation through exchanges of messages
- deferred commitment --
the internal workings of an object can be redefined without changing other parts of the system
- reusability --
refining classes through inheritance
- naturalness --
object-oriented analysis / design, modeling
slide: Benefits of OOP
Although an object-oriented approach to program development
indeed offers great flexibility, some of the problems it addresses are
intrinsically difficult and cannot really be solved by mechanisms alone.
For instance, modularization is recognized to be a notoriously
difficult problem in the software engineering literature.
Hence, since some of the promises of OOP depend upon the
stability of the chosen modularization, the real advantage of OOP may
be rather short-lived.
Moreover, despite the optimistic claims about `tuning' reused code
by means of inheritance, experience shows that often more understanding
of the inherited classes is needed than is available in their specification.
The probability of arriving at a stable modularization may
increase when shifting focus from programming to design.
The mechanisms supported by OOP allow for modeling application
oriented concepts in a direct, natural way.
But this benefit of OOP will only be gained at the price of increasing
the design effort.