comp.lang.ada
 help / color / mirror / Atom feed
* on Ada abtract data type vs. OOP.
@ 2022-09-09  9:32 Nasser M. Abbasi
  2022-09-09 10:49 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Nasser M. Abbasi @ 2022-09-09  9:32 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-11  8:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09  9:32 on Ada abtract data type vs. OOP Nasser M. Abbasi
2022-09-09 10:49 ` Dmitry A. Kazakov
2022-09-09 14:37   ` antispam
2022-09-09 15:21     ` Dmitry A. Kazakov
2022-09-09 15:30   ` Dmitry A. Kazakov
2022-09-09 14:04 ` Jeffrey R.Carter
2022-09-09 15:06 ` antispam
2022-09-11  8:02   ` G.B.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox