Object-oriented Software in Ada 95
Object-oriented Software in Ada 95
Object-oriented Software in Ada 95
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
vi<br />
Contents<br />
4.21 EXERCISES.............................................................................................................................................................59<br />
5 PROCEDURES AND FUNCTIONS ..........................................................................................................60<br />
5.1 INTRODUCTION ...................................................................................................................................................60<br />
5.2 FUNCTIONS...........................................................................................................................................................60<br />
5.2.1 Local variables............................................................................................................................................ 61<br />
5.2.2 Separate compilation of functions............................................................................................................ 61<br />
5.3 PROCEDURES........................................................................................................................................................62<br />
5.3.1 Separate compilation of procedures........................................................................................................ 63<br />
5.4 FORMAL AND ACTUAL PARAMETERS ..........................................................................................................64<br />
5.5 MODES OF A PARAMETER TO A FUNCTION OR PROCEDURE .................................................................64<br />
5.5.1 Example of mode <strong>in</strong> out ........................................................................................................................ 65<br />
5.5.2 Putt<strong>in</strong>g it all together ................................................................................................................................. 65<br />
5.5.3 Summary of access to formal parameters ............................................................................................... 66<br />
5.6 RECURSION...........................................................................................................................................................66<br />
5.6.1 The procedure Write_Natural.......................................................................................................... 67<br />
5.6.2 Putt<strong>in</strong>g it all together ................................................................................................................................. 67<br />
5.7 OVERLOADING OF FUNCTIONS.......................................................................................................................67<br />
5.8 DIFFERENT NUMBER OF PARAMETERS........................................................................................................69<br />
5.9 DEFAULT VALUES AND NAMED PARAMETERS..........................................................................................69<br />
5.9.1 Putt<strong>in</strong>g it all together ................................................................................................................................. 70<br />
5.10 SELF-ASSESSMENT .............................................................................................................................................71<br />
5.11 EXERCISES.............................................................................................................................................................71<br />
6 PACKAGES AS CLASSES ..........................................................................................................................73<br />
6.1 INTRODUCTION ...................................................................................................................................................73<br />
6.2 OBJECTS, MESSAGES AND METHODS ...........................................................................................................74<br />
6.3 OBJECTS, MESSAGES AND METHODS IN ADA ............................................................................................74<br />
6.3.1 An object for a bank account .................................................................................................................... 75<br />
6.3.2 The procedure Statement..................................................................................................................... 76<br />
6.3.3 Putt<strong>in</strong>g it all together ................................................................................................................................. 76<br />
6.3.4 Components of a package.......................................................................................................................... 76<br />
6.3.5 Specification of the package ..................................................................................................................... 76<br />
6.3.6 A class diagram show<strong>in</strong>g a class.............................................................................................................. 78<br />
6.3.7 Representation of the balance of the account........................................................................................ 78<br />
6.3.8 Implementation of the package................................................................................................................. 78<br />
6.3.9 Term<strong>in</strong>ology................................................................................................................................................. 79<br />
6.4 THE PACKAGE AS SEEN BY A USER...............................................................................................................79<br />
6.5 THE PACKAGE AS SEEN BY AN IMPLEMENTOR .........................................................................................79<br />
6.6 THE CLASS............................................................................................................................................................80<br />
6.7 CLAUSES WITH AND USE..................................................................................................................................80<br />
6.7.1 To use or not to use the use clause ........................................................................................................ 81<br />
6.7.2 The package Standard........................................................................................................................... 81<br />
6.7.3 Position<strong>in</strong>g of with and use <strong>in</strong> a package declaration .................................................................... 81<br />
6.7.4 Conflict <strong>in</strong> names <strong>in</strong> a package ................................................................................................................ 82<br />
6.8 MUTATORS AND INSPECTORS.........................................................................................................................82<br />
6.9 TYPE PRIVATE ......................................................................................................................................................83<br />
6.9.1 Type limited private ...................................................................................................................... 83<br />
6.10 INITIALIZING AN OBJECT AT DECLARATION TIME...................................................................................84<br />
6.10.1 By discrim<strong>in</strong>ant ........................................................................................................................................... 84<br />
6.10.2 Restrictions.................................................................................................................................................. 85<br />
6.10.3 By assignment.............................................................................................................................................. 85<br />
6.10.4 Restrictions.................................................................................................................................................. 86<br />
6.11 A PERSONAL ACCOUNT MANAGER ...............................................................................................................86<br />
6.12 CLASS TUI............................................................................................................................................................89<br />
6.13 SELF-ASSESSMENT .............................................................................................................................................91<br />
6.14 EXERCISES.............................................................................................................................................................92<br />
© M A Smith - May not be reproduced without permission