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,900edaa189af2033 X-Google-Attributes: gid103376,public From: Andre Spiegel Subject: Re: Ada95 OOP Questions Date: 1996/07/29 Message-ID: #1/1 X-Deja-AN: 170976183 sender: spiegel@berlin.berlin.informatik.uni-stuttgart.de references: <4tf3l4$4hu@masala.cc.uh.edu> organization: University of Stuttgart, Germany newsgroups: comp.lang.ada Date: 1996-07-29T00:00:00+00:00 List-Id: Spasmo writes: > with Persons; > > procedure Main is > > P : Persons.Person; > > begin > Persons.Walk(P); > Persons.Talk(P); > Persons.Eat(P); > end Main; With a use-clause, it looks better with Persons; use Persons; P : Person; Walk (P); Talk (P); Eat (P); > Correct me if I'm wrong on this. So you're still passing parameters > which means that data and subprograms are still 2 different entities > which sorta hurts the abstraction, rather than in say C++ where > you've got a unified object. You _are_ wrong. The subprograms actually _are_ a part of the object, and they "go" with it, so to speak of, whereever you take the object. It is just less obvious from the syntax in Ada. At the implementation level, C++ does things in just the same way as Ada. The object *is* actually passed as a parameter to its functions, although this parameter (the "this" pointer) is implicitly generated. C++ has a special syntax for method invocation ("p.walk()"), which is converted to a normal function call with "this=p" as the first parameter by the compiler. That is the only difference between C++ and Ada here. (There are a number of implications of this, though; mostly concerning the fact that Ada can bind some calls statically, whereas in C++ you always need to go through the dispatch table in the object. I won't go into detail about this here. Ada gives you finer control about the calling mechanism, that's the point.) When you inherit from a type in Ada (extend the type), you certainly don't need to write the subprograms again -- that's the whole point of inheritance. The do "go" with the type; you only need to rewrite them if you want to change them in the derived type. No difference between Ada and C++ here. The example given in your message is wrong.