9 Data Abstraction and Object Orientation
9 Data Abstraction and Object Orientation
Object Orientation
Figure 9.3 Implementation of virtual methods. The representation of object F begins with the address of the vtable for class foo. (All objects of this class
will point to the same vtable.) The vtable itself consists of an array of addresses, one for the code of each virtual method of the class. The remainder of F
consists of the representations of its fields.
Figure 9.4 Implementationof single inheritance. As in Figure 9.3, the representation of object B begins with the address of its class’s vtable. The first four entries
in the table represent the same members as they do for foo, except that one —m— has been overridden and now contains the address of the code for a different
subroutine. Additional fields of bar follow the ones inherited from foo in the representation of B; additional virtual methods follow the ones inherited from foo in
the vtable of class.
• Java
– interfaces, mix-in inheritance
– alternative to multiple inheritance
• basically you inherit from one real parent and one or
more interfaces, each of which contains only virtual
functions and no data
• this avoids the contiguity issues in multiple inheritance
above, allowing a very simple implementation
– all methods virtual
Copyright © 2009 Elsevier
Object-Oriented Programming
• Is C++ object-oriented?
– Uses all the right buzzwords
– Has (multiple) inheritance and generics
(templates)
– Allows creation of user-defined classes that look
just like built-in ones
– Has all the low-level C stuff to escape the
paradigm
– Has friends
– Has static type checking
Copyright © 2009 Elsevier
Object-Oriented Programming