From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f4d5ed8a41b9fc83,start X-Google-Attributes: gid103376,public From: Oliver.Kellogg@vs.dasa.de Subject: Design of the Ada95 object system Date: 1997/11/25 Message-ID: <880451634.2136@dejanews.com>#1/1 X-Deja-AN: 292482899 X-Http-User-Agent: Mozilla/2.0 (compatible; MSIE 3.02; Windows NT) via proxy gateway CERN-HTTPD/3.0 libwww/2.17 X-Originating-IP-Addr: 53.16.22.2 (gatekeeper.vs.dasa.de) Organization: Deja News Posting Service X-Authenticated-Sender: Oliver.Kellogg@vs.dasa.de X-Article-Creation-Date: Tue Nov 25 09:53:55 1997 GMT Newsgroups: comp.lang.ada Date: 1997-11-25T00:00:00+00:00 List-Id: Having written my first few programs in C++, following question comes to me concerning the object system of Ada95. During the language design, was it ever considered to use the *package* (instead of, as it were, the record type) as the basic object mechanism? It would seem to me that the package constitutes the basic encapsulation mechanism in Ada, and could be viewed as an equivalent of the C++ class. I feel that using the record type as the vehicle of object orientation constitutes a "double encap- sulation" (package declaration scope plus tagged record type declaration scope.) What I have in mind is something like a "tagged package". A tagged package would not in itself constitute an instance (as non-generic packages do), but rather a type declaration. It is of course a matter of taste, but I prefer the notation "Object.Method" for a method invocation (as in C++ et al.) rather than "Method(Object)". This exactly captures the intended encapsulation -- everything inside the tagged package declaration "belongs to" the object. Further, it would be possible to have an implicit "This" or "Self" access value to an instance of a tagged package like in other OOPLs. -- An example could look like this: tagged package My_Object_Type is type Some_Type is new Integer range 0..99; procedure Some_Proc (I : in out Some_Type); XY : Some_Type := 50; -- Type/subprogram/variable declarations as usual end My_Object_Type; -- Here's an example of using the above package: with My_Object_Type; with Text_IO; procedure Main_Program is package My_Object is new My_Object_Type; -- instantiation -- Perhaps the syntax for instantiation should rather be: -- My_Object : My_Object_Type; ? begin My_Object.Some_Proc (My_Object.XY); Text_IO.Put_Line (My_Object.Some_Type'image (My_Object.XY)); end Main_Program; -- Here's an example of extending the tagged package: with My_Object_Type; tagged package My_Extension is new My_Object_Type with Z : Some_Type := 51; procedure Some_Proc (I : in out Some_Type); -- overrides the declaration in My_Object_Type. end My_Extension; I'll be quick to admit that this is not yet well thought out. For example, one criticism that immediately comes to mind is the impossibility to declare an access-to-tagged-package type outside of any enclosing scope. (OTOH, perhaps there's no need for such a type -- need to think about that.) If anyone can refer me to further reading explaining the choice of object mechanism in Ada95, that'd be great. I've already consulted the Ada95 Rationale and found some comparisons with other languages at the end of chapter 4, but not a discussion of alternatives considered for the Ada95 object system during language design. --Oliver Oliver.Kellogg@vs.dasa.de -- These opinions are MINE and do not represent those of DASA -- -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet