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=-0.1 required=3.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC,T_SCC_BODY_TEXT_LINE,URI_TRY_3LD autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!GHezN/6/NNv65i+oFa9rAQ.user.46.165.242.75.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: on Ada abtract data type vs. OOP. Date: Fri, 9 Sep 2022 04:32:18 -0500 Organization: Aioe.org NNTP Server Message-ID: Reply-To: nma@12000.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="59782"; posting-host="GHezN/6/NNv65i+oFa9rAQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:64300 List-Id: 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). Let look at this simple example from https://learn.adacore.com/courses/intro-to-ada/chapters/privacy.html -------------------------- package Stacks is type Stack is private; procedure Push (S : in out Stack; Val : Integer); procedure Pop (S : in out Stack; Val : out Integer); private subtype Stack_Index is Natural range 1 .. 10; type Content_Type is array (Stack_Index) of Natural; type Stack is record Top : Stack_Index; Content : Content_Type; end record; end Stacks; --------------------------- 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? Again, assuming one does not want to do inheritance? For polymorphism one can use generic packages if needed. It seems to me that Ada ADT provides all the benefits of OOP and more, as it does not mix data and methods inside one container. What do other think about this subject? Do you think it is better to do it as OOP, to have the data inside the object, or like with ADT, where the data instances are on the client side? --Nasser