From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!NZ87pNe1TKxNDknVl4tZhw.user.46.165.242.91.POSTED!not-for-mail From: antispam@math.uni.wroc.pl Newsgroups: comp.lang.ada Subject: Re: on Ada abtract data type vs. OOP. Date: Fri, 9 Sep 2022 15:06:51 -0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Injection-Info: gioia.aioe.org; logging-data="40594"; posting-host="NZ87pNe1TKxNDknVl4tZhw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (Linux/5.10.0-9-amd64 (x86_64)) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:0RbTfy6EXceAnKxeso13KplVVVY= Xref: reader01.eternal-september.org comp.lang.ada:64304 List-Id: Nasser M. Abbasi wrote: > Lets say one does not want to do inheritance. (I think it causes > more problems than it solves actually). > > The only difference I see between Ada's ADT and OOP, is that > in Ada, the data itself is separated from the package and must > be passed to the package methods at each call. The data lives > in the client side. > > While in OOP, the data lives inside the object. (these are called > data memebers). > > To use it, The user does > > ------------------------- > -- Example of use > with Stacks; use Stacks; > > procedure Test_Stack is > S : Stack; > Res : Integer; > begin > Push (S, 5); > Push (S, 7); > Pop (S, Res); > end Test_Stack; > --------------------- > > In OOP, the stack itself, would live inside the "module" which will > be the class/object in that case. > > So the above use example will becomes something like this > > > o:=Object(); -- this calls the constructor > o.Push(5); -- data now is stored inside "o" > o.Push(7) > res := O.Pop(); > > So the main difference I see, is that in Ada ADT, the data (the stack > in this example) lives on the client side, and the package > just has the methods. > > For me, this actually better than OOP. Having methods separated > from data is a good thing. > > Is there is something I am overlooking other than this? What you have above is trivial syntactic difference: o.Push(5) versus Push(o, 5) This is really no more difference than o.Push(5) versus o :Push 5 that some OO langues use. All syntaxes above mean call Push (which may be called "function", "procedure", "method", "generic function", etc.) applying it to arguments 'o' and '5'. The real difference is in mechanizm used to determine which code to run. In simplest case (C or Pascal) Push whould have specified argument types and you could not use it with different types. In more complicated case there is overloading which _at compile time_ decides which Push to call. In OO there is dispatch mechanizm which _at runtime_ decides which Push to call. In Ada you normally have overloading. Tagged types use OO dispatch. To see difference runtime type must be different than statically determined type, this is possible due to inheritance. Without inheritance diffences are trivial. -- Waldek Hebisch