From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: problems with classes
Date: Mon, 4 Oct 2004 10:33:19 +0200
Date: 2004-10-04T10:33:19+02:00 [thread overview]
Message-ID: <1gnik0tlsc3av.1i85f33sd3tkx$.dlg@40tude.net> (raw)
In-Reply-To: cjk8e1$7ok$03$1@news.t-online.com
On Fri, 1 Oct 2004 20:41:50 +0200, Rick Santa-Cruz wrote:
>>> If this would be C++, I think I would know the answer... so in C++
>>> "something like this" exists, too. It is called pre-definition of a type.
>>> That means that, for example if I need the name of a type before I wanna
>>> specify it, I can just write:
>>> class MyType; and specify it later. Is this the case in Ada too?
>>
>> Close, but not quite. In your example you define the public view of a type
>> and later define its implementation. What you meant is a forward type
>> declaration, it looks exactly like in C++:
> Yes forward declaration ;).
>
> But if "type Child_Class is new Parent_Class with private;" is not a forward
> declaration then what is it then, or what is the sense of this soruce-line?
To publish the contract. It is a declaration of the public interface of the
type Child_Class. It states:
1. There is a type Child_Class
2. It is a descendant of Parent_Class (maybe an indirect one)
The clients of the package can rely on this contract. Forward declaration
(incomplete type declaration) does not define any completed contract. So
the following is illegal:
package Foo is -- ILLEGAL
type X; -- Incomplete declaration
private
type X is range 1..20; -- Type completion, "full view"
It makes no sense for public clients. No public view of X is defined, but
they cannot look into private. Compare with:
package Foo is -- LEGAL
type X is private; -- True contract, "public view"
private
type X is range 1..20; -- Type completion, "full view"
Also illegal is:
package Foo is -- ILLEGAL
type X; -- Promise to complete it here
type X is private; -- No, I will not
You cannot complete X in the private part, because you have promised that X
will be completed in the public part. So either:
package Foo is -- LEGAL
...
private
type X; -- Incomplete declaration
type X is range 1..20; -- Type completion and full view
or
package Foo is -- LEGAL
type X; -- Incomplete declaration
type X is range 1..20; -- Type completion and full view
private
...
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2004-10-04 8:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-30 21:20 problems with classes Rick Santa-Cruz
2004-10-01 7:35 ` Dmitry A. Kazakov
2004-10-01 18:41 ` Rick Santa-Cruz
2004-10-04 8:33 ` Dmitry A. Kazakov [this message]
2004-10-04 10:19 ` Martin Dowie
2004-10-01 7:58 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox