comp.lang.ada
 help / color / mirror / Atom feed
* Design of the Ada95 object system
@ 1997-11-25  0:00 Oliver.Kellogg
  1997-11-25  0:00 ` Matthew Heaney
  1997-11-28  0:00 ` Mats Weber
  0 siblings, 2 replies; 4+ messages in thread
From: Oliver.Kellogg @ 1997-11-25  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-11-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-25  0:00 Design of the Ada95 object system Oliver.Kellogg
1997-11-25  0:00 ` Matthew Heaney
1997-11-28  0:00   ` Mats Weber
1997-11-28  0:00 ` Mats Weber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox