2.3 Relationships between Program Units

[ Table of Contents ] Prev ] Chapter Overview ] Next ] [ Glossary/Index ]

Program units can be "connected" or "snapped together" using three kinds of relationships:

In the following table the first three rows depict withing relationships (based on with clauses), the fourth row depicts two kinds of parent/child relationships, and the last two rows depict nesting relationships. You have already seen examples of withing relationships (like those depicted in the first row of the table), and you will see many more throughout this volume. You have not yet seen examples of parent/child relationships or nesting relationships, but both kinds of examples appear in this chapter.

Im2-2a.gif (1456 bytes)

Withing-1

Any body of a  library unit  can "with in" any other library unit.

(e.g., procedure A withs in procedure B)

IM2-2b.gif (1523 bytes)

Withing-2

The declaration of any package can "with in" any other library unit.

(e.g., the declaration of package C withs in package D)

Im2-2c.gif (1874 bytes)

Withing-3

Any separately compiled subunit body can "with in" any library unit.

(e.g., function F, which is logically nested in package E, withs in package G)

Im2-2d.gif (2049 bytes)

Parent/Child

Given a library package, new child units (library packages or library subprograms) can be declared, either as public or private children.

(e.g., package K.L is a public child of package K and package K.M is a private child of K, the parent unit)

Im2-2e.gif (1536 bytes)

Nesting-1-step

Any kind of program unit can be a nested unit, one that is implemented or declared and implemented in the body of another unit.

(e.g., procedure N is nested in procedure P)

Im2-2f.gif (1724 bytes)

Nesting-2-steps

Any kind of program unit can be nested in a package by 1) being declared in the package's declaration and 2) implemented in the same package's body.

(e.g., procedure T is declared in the declaration of package S and implemented in the body of S)

Collaborating Program Units

As we have said, a program can be viewed as a collection of program units connected together (in the ways shown above) and collaborating together to perform useful activities. All six of the connecting styles tabulated above are illustrated in the examples of this chapter. The most common way of connecting two units is the "Withing-1" method shown in the first row of the table, where the body of one client unit "withs in" another server unit -- always a library unit. The dashed arrow used to represent withing relationships was chosen because the same graphic symbol is used for a similar purpose in the UML notation [Fowler97], to represent the dependency relationship of one unit upon another.

Related Topics

2.12 Nested Packages 2.13 Child Library Units 2.14 Subunits

[ Back to top of pagePrev ] Next ]