wollud1969
wollud1969

Reputation: 497

Ada: public and private part of specification separated?

I learned that there is a public part and a private part in an Ada specification file (*.ads) and only the public part should be considered of the user of the compilation unit (usually a package).

It is actually not usual to separate the public and private part of the specification in different files?

So, finally, the user of such a package knows about the internals of the packages on specification layer but can not use it. Am I right here?

Thanks and cheers, Wolfgang

Upvotes: 2

Views: 226

Answers (1)

Jacob Sparre Andersen
Jacob Sparre Andersen

Reputation: 6611

No, Ada does not allow you to separate the public and private part of a package specification.

The original chief designer of Ada, Jean Ichbiah, did some work on a language, which actually separated the public, private (data structure) and implementation parts of a package, but this didn't become a part of Ada.

Also:

  • The private part and body of a child package can see the private part of its parent.
  • The specification of a private child package can see the private part of its parent.

... so you can't always just ignore the private part of a package specification completely.

A practical example:

When I write unit-tests, I like to put the test suite in a child package of the package I am testing. That way my test cases are not limited to inspect the public view of the types declared in the package.

Upvotes: 7

Related Questions