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,1dc0d0f1c69afb5a X-Google-Attributes: gid103376,public From: Mike Stark Subject: Re: polymophism Date: 1996/11/21 Message-ID: <329493AD.4A35@gsfc.nasa.gov>#1/1 X-Deja-AN: 197937920 references: <56q99a$5o3@rc1.vub.ac.be> <56skhq$9cg@hacgate2.hac.com> <570f4b$rbu@queeg.apci.net> content-type: text/plain; charset=us-ascii organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Macintosh; I; 68K) Date: 1996-11-21T00:00:00+00:00 List-Id: James O'Connor wrote: > > > In Ada (83 or 95) the standard mechanism for implementing an Object seems to > be to have a package that wraps a type declaration and a set of operations on > that type. The type declaration is typically a record that describes the names and > types of the attributes of the Object. (I'll try to use example code but I haven't > programmed in Ada in years...) > > package Airplane_Package is > > type AIRPLANE_TYPE is private; > > function Get_Tail_Number (Airplane : AIRPLANE_TYPE) returns String; > > procedure Take_Off (Airplane : AIRPLANE_TYPE); > > private > type AIRPLANE_TYPE is record > Tail_Number : STRING (1 .. 20) := ""; > Model_Design_Series : STRING (1 .. 20) := ""; > end record; > > end Airplane_Package; > > with Airplane_Package > > procedure Test is > > My_Airplane : Airplane_Package.AIRPLANE_TYPE; > My_TailNumber : STRING (1 .. 20); > > begin > > My_TailNumber := Airplane_Package.Get_Tail_Number(My_Airplane) > > end Test; > > My question is "where's the object?" My_Airplane isn't an object because > it only defines the state of an Airplane. It does not define the operations > available for the Airplane. The package defines the operations. But the package > isn't an object (the package doesn't even have runtime existance). In this case > you could say that the package is close to being a class. A better question might be "where's the class?" The answer is that your private record type is analogous to a C++ or Java class (can't speak for any other languages), with the components representing instance variables and "primitive operations" the member functions. The primitive operation is a concept added for Ada 95, and it is one in the same package as your record type that has an argument of that type. Then My_Airplane in procedure test is indeed an object, although you could also create type Airplane_Ptr is access Airplane_Type; -- in Airplane_Package and My_Airplane: Airplane_Package.Airplane_Pointer := new Airplane_Package.Airplane; to allocate an object. To be truly analogous to a class in C++ or Java, you need to use the Ada 95 "tagged" keyword to make types extendable, and class-wide programming to define dispatching operations. I will leave the description of these features to the experts. This is more than a theoretical discussion. I have been doing some prototyping with AppletMagic, a tool that compiles Ada into Java byte codes. When you run the "javap" command to disassemble a class file into Java source, Ada code containing a tagged record maps directly to a Java class. Mike Note I don't want to get into the fruitless religious war over whether The_object.Do_something (now); or Do_Something (The_Object, Now) is better.