comp.lang.ada
 help / color / mirror / Atom feed
From: antispam@math.uni.wroc.pl
Subject: Re: on Ada abtract data type vs. OOP.
Date: Fri, 9 Sep 2022 15:06:51 -0000 (UTC)	[thread overview]
Message-ID: <tffkqb$17ki$1@gioia.aioe.org> (raw)
In-Reply-To: tff174$1qc6$1@gioia.aioe.org

Nasser M. Abbasi <nma@12000.org> 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).
> 
<snip>
> 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

  parent reply	other threads:[~2022-09-09 15:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-09-11  8:02   ` G.B.
replies disabled

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