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
In OOP, the stack itself, would live inside the "module" which will
be the class/object in that case.
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?
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?
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).
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).
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?
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.
In more formal terms OO is mainy about
_dynamic_ subtyping.
- Ada 2005 added castrated Java-esque multiple dispatch^^^^^^^^ inheritance,
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.
OOP is poop.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 71:12:38 |
Calls: | 8,084 |
Calls today: | 2 |
Files: | 13,069 |
Messages: | 5,849,950 |