High-integrity object-oriented programming with Ada – Part 2

Benjamin M. Brosgol, AdaCore

July 27, 2011

Benjamin M. Brosgol, AdaCoreJuly 27, 2011

Part 1 in this three-article series described how object-oriented programming (OOP) introduces a number of vulnerabilities that need to be mitigated if OOP is to be used successfully in high-integrity applications. Here, we summarize the main elements of Ada’s OOP model. This article is based on object orientation features found in versions of the language up to and including Ada 2005. Part 3 will detail the tools Ada offers to help developers meet the OOP challenge

The foundations for OOP were laid down in the earliest version of the Ada language, Ada 83, with the concepts of packages, objects, and encapsulation. It was the Ada 95 standard, however, that introduced the major OOP functionality: classes/tagged types, inheritance, polymorphism, and dynamic dispatch. In fact, Ada 95 was the first object-oriented language to achieve international (ISO) standardization. Its OOP support was extended in Ada 20051,2,3 with the addition of Java-like interfaces, interdependent classes, and traditional object-oriented notation for operation invocation. The upcoming Ada 2012 version of the language4 adds further enhancements, most notably contract-based programming, that can be used with OOP.

Tagged Types
A class serves two main purposes: as a data template and as a module. Ada has distinct mechanisms for these concepts: data types and packages, respectively. A class is thus modeled by a specific kind of data type—a tagged type—declared within a package specification.

Tagged types generalize record or struct types in other languages. A class’s state data correspond to fields in the tagged type. A class’s inheritable operations are the subprograms directly declared within the same package specification as the tagged type, with a formal parameter or (for functions) a result whose type is the tagged type. Such subprograms are known as the tagged type’s primitive operations. An object is an instance of a tagged type. (Ada actually uses the term “object” more generally, to mean an instance of any data type.)

Syntactically, Ada displays a major difference from languages such as C++ and Java that use the class as a combination module and data type. An Ada tagged type does not contain its primitive subprograms as “members”; rather, they are declared outside the type but in the same package specification.

The term “tagged type” reflects that each of its objects includes (is tagged with) an identification of the type. A typical implementation of the tag is a pointer to a table of the type’s primitive operations sometimes referred to as a vtable, for efficiency of dynamic dispatch.

< Previous
Page 1 of 4
Next >

Loading comments...

Most Read

  • No Articles

Most Commented

  • Currently no items

KNOWLEDGE CENTER