Christoph Karl Walter Grein

A noble principle of sound software engineering is information hiding. It requests to hide everything beyond the programmer's need to know. Also Lady Ada loves to be secretive; she is a perfect mystery-monger.

By derivation from the predefined type Ada.Finalization.Controlled, a class of controlled types is declared arising from the ancestor type Root. Controlledness is a new Ada95 feature giving us additional control over the three fundamental operations on objects: creation, assignment, destruction - associated to the three procedures Initialize, Adjust and Finalize. The exact definition can be found in the Ada RM chapter 7.6 User-Defined Assignment and Finalization. We will look at the behaviour of controlled types with the following simple main program:

Here essentially the following happens:

Let us summarize the sequence of events:

 Initialize called for object of type Root  »  Initialization of Root part of Nothing 
 Initialize called for object of type Something  »  Initialization of the local variable Thing 
 Body of Try_It begins now.
 Finalize called for object of type Something  »  Pre-assignment finalization of Thing 
 Adjust called for object of type Something  »  Post-assignment adjustment of Thing 
 Body of Try_It ends now.
 Finalize called for object of type Something  »  End of scope of Thing 
 Finalize called for object of type Something  »  End of scope of Nothing 

The other day, Lady Ada received a desperate letter from one of her newer admirers. He sent her a little programm he had written, and wrote:

"Dear Lady Ada,

as you can see from the attachment, I have done exactly the same as you, however with a result that is totally unexpected for me, unexperienced disciple that I am - it is true, it is similar to the above, however none of the three operations for Something are called, instead always those for Root. Why?

Begging for enlightenment I remain your most obedient servant, ..."

A compilable and executable (German) program version can be downloaded here.

Solution © Copyright 2000 C.K.W. Grein