Next

Ada 95: The Craft of Object-Oriented Programming

by

John English

(originally published by Prentice Hall, 1997)

Copyright © John English 2001. All rights reserved.


Permission is given to redistribute this work for non-profit educational use only, provided that all the constituent files are distributed unchanged and without charge.


This book, originally published by Prentice Hall in 1996, was taken out of print in 2001 and the rights to the book were subsequently returned to me by Pearson (the successor company to Prentice Hall). I have decided to make it available online in HTML format, and at the same time I have corrected several errata which were present in the printed editions of the book. It’s perfectly possible that I might have missed some, or even introduced some brand-new ones, as part of the process of transforming the text into HTML. If you spot any mistakes, please let me know so I can correct the master copy, which can be found at http://www.it.bton.ac.uk/staff/je/adacraft/.

Downloadable copies are available as http://www.it.bton.ac.uk/staff/je/adacraft/bookhtml.zip (in zip format for Windows systems) or as http://www.it.bton.ac.uk/staff/je/adacraft/bookhtml.tar.gz (a gzipped tarball for Unix systems). Each distribution also includes the complete set of examples from the book, both for Windows (adacraft.zip) and for Unix (adacraft.tar.gz).


Contents

Preface

Part One: Fundamentals

1. Programming concepts
1.1 What is a program?
1.2 Readability, maintainability, portability and reusability
1.3 Specifications and implementations
1.4 Abstract data types
1.5 Generics
1.6 Inheritance and polymorphism
2. Fundamentals of Ada
2.1 Hello, world!
2.2 Names in Ada
2.3 Program layout
2.4 Context clauses
2.5 Strings
2.6 A simple calculator
2.7 Procedure specifications
Exercises
3. Statements
3.1 If statements
3.2 Assignment statements
3.3 Compound conditions
3.4 The case statement
3.5 Range tests
3.6 The null statement
3.7 Loops
3.8 The calculator program revisited
3.9 Exception handling
Exercises
4. Procedures, functions and packages
4.1 Zeller's Congruence
4.2 Declaring procedures
4.3 Declaring functions
4.4 Scope and lifetime
4.5 Separate compilation
4.6 Subprograms as library units
4.7 Packages
4.8 Child packages
Exercises
5. Defining new data types
5.1 Standard data types
5.2 Integers
5.3 Subtypes
5.4 Derived types
5.5 Modular integers
5.6 Real types
5.7 Numeric literals
5.8 Constants
5.9 Enumerations
5.10 The type Boolean
5.11 The type Character
5.12 Renaming declarations
Exercises
6. Composite data types
6.1 Record types
6.2 Strings
6.3 Declaring array types
6.4 Unconstrained types
6.5 For loops revisited
6.6 A simple sorting procedure
6.7 Multidimensional arrays
6.8 Discriminants
6.9 Limited types
6.10 Using packages with data types
Exercises
7. Exceptions
7.1 The importance of exception handling
7.2 Declaring exceptions
7.3 Re-raising exceptions
7.4 Getting information about exceptions
7.5 File input/output
Exercises
8. Program design and debugging
8.1 Stepwise refinement
8.2 Initial design
8.3 Diary package design
8.4 Debugging the main program
8.5 Displaying the appointments
8.6 Adding new appointments
8.7 Deleting appointments
8.8 Loading and saving
8.9 Assessing the program
Exercises

Part Two: Abstract Data Types

9. Private types
9.1 The need for abstraction
9.2 Package design
9.3 Private types
9.4 Full and partial views
9.5 Deferred constants
9.6 The package body
9.7 Overloaded operators
9.8 ‘Use type’ clauses
9.9 A word of caution
9.10 The package Ada.Calendar
Exercises
10. Designing with abstract data types
10.1 The design process revisited
10.2 Separating out the user interface
10.3 Designing the model
10.4 Defining the view package
10.5 Implementing the ADT packages
10.6 Diary operations
10.7 Maintenance issues
Exercises
11. Dynamic memory allocation
11.1 Access types
11.2 Linked lists
11.3 Doubly linked lists
11.4 Iterators
11.5 Deallocating memory
11.6 Designing a linked list diary
11.7 Implementing a linked list diary
11.8 General access types
11.9 Access parameters and discriminants
Exercises
12. Generics
12.1 Generic packages
12.2 Generic parameters
12.3 Revising the diary package
12.4 A generic sorting procedure
12.5 Generics and general access types
Exercises
13. Building a calculator
13.1 Handling operator precedence
13.2 A stack package
13.3 An improved calculator
13.4 Implementing the stack package
13.5 Opaque types
13.6 Formalising the syntax of expressions
13.7 A recursive descent parser
Exercises

Part Three: Designing extensible software

14. Tagged types
14.1 Extending existing software
14.2 Variant records
14.3 Tagged types
14.4 Inheriting primitive operations
14.5 A package for representing meetings
14.6 The dangers of inheritance
14.7 Inheritance or containment?
Exercises
15. Polymorphism and dispatching
15.1 Class-wide types
15.2 Dispatching
15.3 Abstract types
15.4 An object-oriented diary
15.5 Stream input/output
15.6 Other diary operations
15.7 Extending the diary
Exercises
16. Controlled types
16.1 Memory leaks
16.2 User-defined finalisation
16.3 Smart pointers
16.4 User-defined assignment
16.5 Testing controlled types
Exercises
17. An object-oriented calculator
17.1 Expression-handling objects
17.2 Tokens
17.3 Token extraction
17.4 Expression evaluation
17.5 Was it worth it?
Exercises
18. Designing a spreadsheet
18.1 Spreadsheets
18.2 Defining the program
18.3 The spreadsheet class
18.4 Cell implementation
18.5 Formula cells
18.6 Deriving a new expression type
Exercises
19. Multitasking
19.1 Active objects
19.2 Task types
19.3 Communicating with tasks
19.4 More about select statements
19.5 Transferring data during a rendezvous
19.6 Sharing data between tasks
19.7 An active spreadsheet
Exercises
20. Loose ends
20.1 Other features of Ada
20.2 Other sources of information

Appendices

A. Language summary
A.1 Compilation units
A.2 Statements
A.3 Declarations
A.4 Type declarations
A.5 Exceptions
A.6 Expressions
A.7 Generics
A.8 Multitasking features
A.9 The Ada type hierarchy
B. Selected standard packages
B.1 The hierarchy of the standard packages
B.2 The package Standard
B.3 The package Ada.Text_IO
B.4 The package Ada.Sequential_IO
B.5 The package Ada.Streams.Stream_IO
B.6 The package Ada.Characters.Handling
B.7 The package Ada.Characters.Latin_1
C. Language-defined attributes
D. Package Listings
D.1 JE
D.2 JE.Appointments
D.3 JE.Appointments.Meetings
D.4 JE.Appointments.Deadlines
D.5 JE.Diaries
D.6 JE.Expressions
D.7 JE.Expressions.Spreadsheet
D.8 JE.Lists
D.9 JE.Menus
D.10 JE.Pointers
D.11 JE.Spreadsheets
D.12 JE.Spreadsheets.Active
D.13 JE.Stacks
D.14 JE.Times

Glossary


Revision history

    $Log: contents.htm $
    Revision 1.2  2001/11/17 12:00:00  JE
    An astonishing number of errors in both the text and the formatting
    have now been fixed. I am particularly indebted to Tad Ashlock and
    Jeffrey Cherry for sending me extremely detailed lists of problems
    and corrections.

    Revision 1.1  2001/09/12 11:00:00  JE
    Initial revision



Next