18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

168 Child libraries<br />

11.2 Visibility rules of a child package<br />

The private part of a child package can access all components of its ancestors, even the private components.<br />

However, the visible part of a child package has no access to the private components of its ancestors. This is to<br />

prevent possible renam<strong>in</strong>g allow<strong>in</strong>g a client direct access to the private components of one of the child’s<br />

ancestors.<br />

A child package allows a programmer the ability to extend an exist<strong>in</strong>g package without the need to change or<br />

re-compile the package.<br />

For example, Figure 11.1 illustrates a hierarchy of package specifications rooted at package P. The ancestor of<br />

packages P.C2 and P.C1 is package P, whilst the ancestors of package P.C2.G1 are the packages P.C2 and P.<br />

P<br />

Child<br />

Parent<br />

P.C1<br />

Visible Spec.<br />

Private Spec.<br />

Body<br />

Figure 11.1 Illustration of the hierarchy of child units.<br />

Visible Spec.<br />

Private Spec.<br />

Body<br />

P.C2<br />

Grand child<br />

Visible Spec.<br />

Private Spec.<br />

Body<br />

Key Package specification Package body<br />

Components<br />

of a package<br />

<strong>in</strong> this case<br />

package P.<br />

package P is<br />

-- Visible specification.<br />

private<br />

-- Private specification.<br />

end P;<br />

package body P is<br />

-- Body of package<br />

end P;<br />

P.C2.G1<br />

Visible Spec.<br />

Private Spec.<br />

Body<br />

Child<br />

Can access <strong>in</strong> -> P P.C1 P.C2 P.C2.G1<br />

P.C1<br />

Visible spec.<br />

Visible specification<br />

•<br />

P.C1<br />

Private specification<br />

P.C2.G1<br />

Visible specification<br />

P.C2.G1<br />

Private specification<br />

Visible spec.<br />

Private spec.<br />

Visible spec.<br />

Visible spec.<br />

Private spec.<br />

•<br />

Visible spec.<br />

when<br />

with’ed<br />

Visible spec.<br />

when<br />

with’ed<br />

Visible spec.<br />

when<br />

with’ed<br />

Visible spec.<br />

when<br />

with’ed<br />

Visible spec.<br />

Visible spec.<br />

Private spec.<br />

Visible spec.<br />

when<br />

with’ed<br />

Visible spec.<br />

when<br />

with’ed<br />

•<br />

•<br />

Note:<br />

A with clause for a child package implies a with clause for all its ancestors.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!