Lectures Ada_2

Lectures Ada_2 - vii) Derived Types: They allow the...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
vii) Derived Types: They allow the definitions of new types driven from existing types. Even though the derived types inherit the parent type’s operations, they are not compatible (logically distinctive)! To make them compatible we need to use explicit conversion. type PERCEN is new INTEGER range 0..100; P : PERCEN; I: INTEGER; P:= I; -- illegal also I := P; -- illegal But: P := PERCEN(I); -- is legal I := INTEGER(P); -- is legal PACKAGES Packaging ” is a basic data abstraction and modularity mechanism in Ada for grouping logically related data values and their associated set of operations (ADT), forming an environment that can be accessed via mutual consent between the user and the implementer of the package. i) Package Interface ( Specification ): package <NAME> is -- visible section : objects and type declarations; procedure/function headers [ -- private section: optional section that has private types and all deferred constructs concrete declarations. It is to be seen by the compiler not by the users, for optimal space allocation by the compiler. ] end [(optional) <NAME>]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ii) Package Body ( Implementation ): package body < NAME> is [ -- optional: 1) local declarations, invisible to the users 2) concrete implementation of the procedures and functions package operations (above). ] [--Optional section that with some Ada statements, e.g., for initialization ] [ exception -- Optional section that with Ada exception handlers ] end [ (optional) <NAME>]; Package’s “Specification” and “Body” can be compiled separately (same as in Modula-2) . A package can be lib module , or nested within a subprograms . Packages can be a lib modules and separate compilation units. Private ” types are similar to the Modula-2 “ opaque ” types, since the user can not access their concrete implementation for true ADTs. There is no explicit “import/export” commands, yet the idea of mutual consent (user/implementer) visibility still holds, all names defined at the package interface and outside the private section are visible to the package’s users (i.e., public names). To invoke a lib package we use the “ with ” clause, in the declaration of other subprograms: with <package-name> ; and we utilize the “ use ” clause to make the package name visible in the code with no need for prefixing all of its operations with its name via the dot notation, i.e., <package- name>.<operation-name>. use <package-name>; Notice: the with must be before the use !
Background image of page 2
Generic Packaging Facility: (Static Genericity) A second order static polymorphism (power) to textually group a number of different versions of an ADT (e.g., based on elements’ types or numbers) into one “generic” parameterized
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/23/2011 for the course CSE 324 taught by Professor Soliman during the Spring '11 term at NMT.

Page1 / 8

Lectures Ada_2 - vii) Derived Types: They allow the...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online