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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,155b49c9f46f66ec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-11-27 07:04:01 PST Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!pipex!uunet!news.gcr.com!mandolin.gcr.com!not-for-mail From: dodger@gcr.com (Roger Labbe) Newsgroups: comp.lang.ada Subject: Re: don't understand packages vs. objects/classes Date: 27 Nov 1994 09:58:38 -0500 Organization: Genuine Computing Resources 703-551-0095 login: guest Message-ID: <3ba6qu$6rs@mandolin.gcr.com> References: NNTP-Posting-Host: mandolin.gcr.com X-Newsreader: NN version 6.5.0 #3 (NOV) Date: 1994-11-27T09:58:38-05:00 List-Id: As declared, you cannot have two or more stacks. The key is to define a data type called stack and encapsulate it in a package (which I'll call STACKS in a failure of creativity). THus you might have: -- Lame implementation without error handling or other necessary stuff. generic type element is private; package STACKS is type stack is private; procedure push (s : stack; value : element); ... rest of spec end STACKS; Then in your procedure you can declare package int_stack is new stacks (element => integer); package float_stack is new stacks (element => your_float); x : int_stack; y, z : float_stack; begin push(x, 3); Now whether you want to consider this library based or object based is up to you. But how different is the C++ equivalent stack x; x.push(3); The x is outside the push instead of a parameter as in Ada, but I consider the code equivalent (as far as this example goes). As far as class hierarchies go Ada 83 doesn't really have them. You can use derived types to inherit operations and add operations, but you cannot add new components. Briefly, Ada 94 allows tagged types which may be extended by derivation to add new components. This is a topic that is too complex for a single post, and probably not to important to someone just learning the language. But yes, packages in Ada 83 are limited; they are better at implementing encapsulation than object oriented features. Get the Ada 9x rationale from the Ada web server if you want to read a good introduction to Ada 94 and object oriented programming. I don't have the address right here, but you can find it easily in the newsgroup; alternatively, send me email and I'll send it to you. Roger Labbe