4.4.1 Abstract data types.
The Device example above provides the basis for an abstract data type, this method for object based programming has been well known and understood for years, the creation of an encapsulated type with a set of operations - the forerunner to today's object-oriented programming systems. Let us consider an example:
with Ada_Store_PoST_Device; with System_Printer; procedure Device_Test is The_Device : Ada_Store_PoST_Device.Instance; The_Printer : System_Printer.Instance; begin Ada_Store_PoST_Device.Open(The_Device, 1); System_Printer.Open(The_Printer, "A4.Drilled"); Ada_Store_PoST_Device.Write(The_Device, ..); System_Printer.Write(..); Ada_Store_PoST_Device.Read(The_Device, ..); Ada_Store_PoST_Device.Close(The_Device); end Device_Test;
This may not seem very clever to C++ programmers, but it is as big a leap forward from C as C++ classes, it solves namespace problems, and provides a level of encapsulation previously not possible with C. Note how the package name becomes a type name so you get in effect:
Type_Name.Operation(Instance, Args ..);
Also we have used a convention of naming the primary type of a package Instance, again this becomes very readable when you look at the declarations for The_Device, you request an instance of Ada_Store_PoST_Device. This readable abstract data type concept is very powerful and is used to great effect to package objects and as yet we have not touched on true object oriented programming in any way.
Copyright ©
1996 Simon Johnston &
Addison Wesley Longman