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 14:37:55 -0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Injection-Info: gioia.aioe.org; logging-data="12201"; 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)) Cancel-Lock: sha1:Hw6+NsJTZx9cygWT4O4mKmc883o= X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:64303 List-Id: Dmitry A. Kazakov wrote: > On 2022-09-09 11:32, Nasser M. Abbasi wrote: > > - tagged extension: type S is new T with ...; > - subtype constraining: subtype S is T; > - cloing: type S is new T; > > > 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. > > This applies to all types and has nothing to do with ADT or OO. A state > can be either localized in an object (good design) or kept outside it in > global variables (bad design). > > > While in OOP, the data lives inside the object. (these are called > > data memebers). > > Just like in any type, not even abstract one. E.g. > > type X is range 1..100; > > The "data" live in each instance of X. > > > Let look at this simple example from > > [...] Stack example > > > In OOP, the stack itself, would live inside the "module" which will > > be the class/object in that case. > > No, OOP example of stack is exactly the one you cited. There is a type > Stack and operations of. A non-OO/ADT stack would be: > > generic -- No parameters!! > package Generic_Integer_Stack is > procedure Push (Val : Integer); > procedure Pop (Val : out Integer); > > You get a stack instance this way: > > package Integer_Stack is new Generic_Integer_Stack; > > > 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. > > The sentence does not make sense to me. OO is ADT. I am not sure which > issue you have problem with: > > - No local states > - Stateful vs stateless > - Interface vs implementation inheritance Your statement is _very_ misleading. OO has many common aspects with ADT, but there is substantial difference. One may have prefecty fine ADT without having OO or vice versa (of course Ada provides both so one may overlook the difference). To explain more, OO in mainly about inheritance and related dynamic dispatch. In more formal terms OO is mainy about _dynamic_ subtyping. To give an example, let me generalize stack example from previous post. This in not Ada, so I skip most details just giving conceptsWe may have abstact interfaces BagAggregate. StackAggregate and QueueAggregate. Both StackAggregate and QueueAggregate inherit from BagAggregate. The interfaces and actual type are parametrized and there is a type Stack(Integer) which is a type exporting StackAggregate(Integer). This is abstract type, all you can do with it is declared in the inteface. You can use Stack(Integer) in places that statically need BagAggregate(Integer). You also have Queue(Integer) which exports QueueAggregate(Integer). You can use Queue(Integer) in places that statically need BagAggregate(Integer). Up to now this may look like normal OO with inheritance. But there is signicifant difference. You can form List(Stack(Integer)), that is have list of stacks. You can form List(Queue(Integer)) that is have list of queues. But you can _not_ have List(BagAggregate(Integer)). In OO design you could do this or some eqivalent to have a list containg both stacks and queues. -- Waldek Hebisch