LECTURE 12 Introduction to Ada 95 586 A short wrap up of the course, then a quiz. Structuring large programs... Parallel to a project organization.. Set up a package specification ( no body ) that contains all Ada TYPE and SUBTYPE specifications that are global to the total program. This package will be WITHed by all compilation units that use global types . Set up a package specification ( no body ) that contains all global objects. This includes arrays,records,pointers, etc. all data that requires memory global to the total program. This package is WITHed by all compilation units that use or set global data. These two packages may be combined if the size is reasonable. Assuming the total program can be divided into major sections where there is considerable interaction within each section and some interaction with other sections , Set up similar packages to the global packages for each section. At this point the major type and data structures are defined. Individual procedures can be written and compiled . The normal good programming practice is to have one logical function performed by a procedure or function. Groups of related procedures should be combined in a single package as long as it does not get too big. The use of "separate" compilation can keep the physical size of files reasonable. A small example of this technique is shown on the next page. Tasks should physically reside in a package. An independent task may be alone in a package. Related tasks should be combined in a single package as long as it does not get too large. Tasks can be kept small by calling procedures to do the work for the tasks. Some guidelines on the use of use clauses. Recognize there is a tradeoff between speed of development verses ease of reading. Always using the use clause makes rapid prototyping work. Never using the use clause makes the program most traceable in the sense you can tell where everything comes from. Traceability may not be what some people would call easy reading. Recognize that naming conventions interact with use clauses. Unbounded_Stack.Push ( Item ) is an example where the package name is very descriptive and the procedure name is descriptive in the context of being a selected component of the package. Note, the procedure name does not duplicate the package definition. An Ada Guru made the following observation: Never use use clauses on objects. You can get into trouble. Minimize the use of use clauses on procedures and functions. Always use use clauses on types and subtypes. A type is a set of values and a set of operations on these values. This includes operator functions "+", "_" etc. As seen by the following subsystems example, place with clauses on a specification only if absolutely necessary. Place the with clauses on the body when needed. This is an example of using "separate" compilation to keep the physical size of a package body small. The trade off is to have more files with less in each file, yet maintain the same Ada organization. $ TYPE ANY_PACKAGE_.ADA package ANY_PACKAGE is -- specification -- type and object declarations as required procedure SOME_PROCEDURE ( X : INTEGER ) ; function SOME_FUNCTION ( X : FLOAT ) return INTEGER ; task SOME_TASK is -- entries end SOME_TASK ; -- ... many more procedure, function , task specifications end ANY_PACKAGE ; $ TYPE ANY_PACKAGE.ADA package body ANY_PACKAGE is -- package body with no code ! procedure SOME_PROCEDURE ( X : INTEGER ) is separate ; function SOME_FUNCTION ( X : FLOAT ) return INTEGER is separate ; task body SOME_TASK is separate ; -- ... many more procedure, function , task specifications -- same as in specification with is separate added end ANY_PACKAGE ; $ TYPE ANY_PACKAGE__SOME_PROCEDURE.ADA separate ( ANY_PACKAGE ) procedure SOME_PROCEDURE ( X : INTEGER ) is -- declarations begin -- lots of code may go here null ; end SOME_PROCEDURE ; $ TYPE ANY_PACKAGE__SOME_FUNCTION.ADA separate ( ANY_PACKAGE ) function SOME_FUNCTION ( X : FLOAT ) return INTEGER is -- declarations begin -- lots of code may go here return INTEGER ( X + 0.5 ) ; end SOME_FUNCTION ; $ TYPE ANY_PACKAGE__SOME_TASK.ADA separate ( ANY_PACKAGE ) task body SOME_TASK is -- declarations begin -- lots of code may go here null ; end SOME_TASK ; OO ... This is about Object Oriented Typically, Object Oriented Design Object Oriented Requirements Analysis Object Oriented Programming ... The key concepts are: INHERITANCE multiple inheritance packages, child packages generic packages tagged types DATA ABSTRACTION information hiding package, private in Ada tagged types discriminated records POLYMORPHISM Overloading access to subprogram Ada 95 may not be an exact match for what is desired, but it can be used as effectively as C++ or SmallTalk or other OOP languages.