Summary
This first example of a complete program pulls together various aspects of the type Object and its descendants which were discussed in Chapter 3. This opening description is followed by the text of the program and then some notes on specific points.
The program is in two phases. It first reads in the dimensions of a number of objects and then computes and prints out a table of their properties.
The root package Geometry contains the abstract type Object together with various abstract operations. The function MI is the moment of inertia of the object about its centre (see Exercise 3.3(5)). The function Name returns a string describing the type of the object. Each of the concrete types is then declared in its own child package.
The child package Geometry.Circles declares the type Circle which is derived from the abstract type Object and has one additional component, Radius. It also declares concrete functions Area, MI and Name which implement the corresponding abstract operations of the root type Object.
The child packages Geometry.Points, Geometry.Triangles, and Geometry.Squares then similarly declare types Point, Triangle, and Square with appropriate concrete functions.
There are also a number of other child packages containing related material. The package Geometry.Magic contains the class wide functions Moment and MO; Moment gives the vertical moment about the origin whereas MO gives the moment of inertia about the origin. The package Geometry.Lists contains entities for defining and manipulating lists of objects.
- Type
- Chapter
- Information
- Programming in Ada 2012 , pp. 59 - 62Publisher: Cambridge University PressPrint publication year: 2014