help / color / mirror / Atom feed
Subject: Re: on Ada abtract data type vs. OOP.
Date: Fri, 9 Sep 2022 14:37:55 -0000 (UTC)	[thread overview]
Message-ID: <tffj43$bt9$> (raw)
In-Reply-To: tff5na$1vc8$

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

  reply	other threads:[~2022-09-09 14:37 UTC|newest]

Thread overview: 10+ 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 [this message]
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.
2024-04-19 16:25 ` Nioclás Pól Caileán de Ghloucester
2024-04-19 22:05   ` Lawrence D'Oliveiro
replies disabled

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