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.9 required=5.0 tests=BAYES_00 autolearn=ham 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: cosc19z5@Bayou.UH.EDU (Spasmo) Subject: Re: Ada95 OOP Questions Date: 1996/07/28 Message-ID: <4tgi88$5fi@Masala.CC.UH.EDU> X-Deja-AN: 170700495 references: <4tf3l4$4hu@masala.cc.uh.edu> organization: University of Houston newsgroups: comp.lang.ada Date: 1996-07-28T00:00:00+00:00 List-Id: Andre Spiegel (spiegel@berlin.informatik.uni-stuttgart.de) wrote: : Spasmo writes: : > Well after looking at Barnes' Ada95 book and checking out the : > OOP sections I noticed that the Objects in Ada95 seem to : > consist purely of data, and no methods seem to be involved : > so that you have to pass these objects to functions in order : > to get stuff done. Am I wrong in this (or did I somehow : > miss something again?). [Snip] : So, to translate your C++ example into equivalent Ada (not just : "simulating" it!), you can write : package Persons is : type Person is tagged private; : procedure Walk (P : Person); : procedure Talk (P : Person); : procedure Eat (P : Person); : private : type Person is tagged : record : Age : Integer; -- rather "Natural", I'd suggest : -- (C++ doesn't have this) Or even better, a subtype. That's what I like about Ada. : Name : String (1..256); : end record; : end Persons; Well here's the thing though, from what I'm seeing when you use the package you'd need to pass the parameters to the subprograms rather than having the data encapsulated. For instance in C++ you'd do the following: Person p; p.walk(); p.talk(); p.eat(); But with the above you'd do something like the following: (Any Ada code provided may be slightly erroneous, I just want to give a general idea of what I think I understand hence not checking much). with Persons; procedure Main is P : Persons.Person; begin Persons.Walk(P); Persons.Talk(P); Persons.Eat(P); end Main; 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. That's pretty much what I was talking about. I'm not saying that one is necessarily worse than the other, I was just wondering if there was a rationale for doing it that particular way in Ada rather than a unified object that was like a combination of data and subprograms that enabled it to smoothly simulate an entity? Also there's another slight difference -- inheritance. From what I'm seeing, if we wanted to create say a SuperPersons package that inherited from persons we'd create a new package called SuperPerson, then we'd with the Persons package, and provide "wrappers" for everything defined in the Persons package right? Then we'd of course inherit from the data types and add in any new functionality that we wanted to, am I correct? For example here's a crude idea of what I'm talking about: with Persons; package SuperPersons is type SuperPerson is tagged private; procedure Walk(SP : SuperPerson); procedure Talk(SP : SuperPerson); procedure Eat(SP : SuperPerson); private type SuperPerson is new Persons.Person with record SuperPowers : Power; end record; end SuperPersons; then all our procedures like Walk, Talk, Eat, etc... would need to call their predecessors right? For instance: package body SuperPersons is procedure Walk(SP : SuperPerson) is begin Persons.Walk(SP); end Walk; ... end SuperPersnos; and so forth (we could inline them) Am I correct or can we in fact inherit operations without manually providing wrappers for the predecessors? : What should be pointed out is that C++ and Ada use slightly different : abstractions. In C++, you have "classes" and "objects" (but sometimes : a class is referred to as an object, too); whereas in Ada you have : "packages", "types", "classes of types", and "objects". For a very : good discussion of this, see Tucker Taft's answer to Question 5.1 in : the Ada Programming FAQ (http://lglwww.epfl.ch/Ada/FAQ/programming.html). Well what I learned in C++ was that "class" referred to the declaration/ definition, whereas an object is an instance of a class. So using my old example, Person is a class, but p is an object since it's an instance of Person. Still that is kinda moot since we're more concerned with Ada rather than C++. I'll look at Question 5.1 again (I skimmed over certain parts of the FAQ last time I read it which was when I was trying to find out more about Ada to see whether or not I'd want to program in it). : Hope this helps, It did, thanks. : Andre Spiegel : University of Stuttgart, Germany -- Spasmo "Everyone has secrets, but sometimes you get caught, So if it's just between us, my silence can be bought" "Blackmail" by Sloppy Seconds