comp.lang.ada
 help / color / mirror / Atom feed
From: "per" <commander@death-star.com>
Subject: Re: OO problem: Performing actions on messages (very long, sorry)
Date: 3 Jan 2005 04:37:03 -0800
Date: 2005-01-03T04:37:03-08:00	[thread overview]
Message-ID: <1104755823.837077.74630@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: 1qdvdjid4u58v.1xz6j5ec6nfcy$.dlg@40tude.net

Dmitry:

>> Somewhere some mechanism assigns the initial values:
>> M1 : Message.M1.Instance;
>> Put_A(M1, 1.0);
>> Put_B(M1, 1);
>> ...

>> Later on, an override action shall be able to override these values
by
>> basically doing:

>> Put_A(M1, Some_Other_Value_Stored_In_The_Action);

>> again!

>And why: M1.A := 10; is bad?

Hm.

1. Action does not know of the internals of M1 (such as that M1.A
exists)
2. Action should cope with any Message (M1, M2, etc).
3. Action should cope with any type of the field to overwrite.
4. The value to overwrite _with_ is determined at run-time (by the
user).

But I really don't care if I write ":=" or "Put_"; that's not the
issue.

I just want to be able to call a specific Put_... (or do ":=") on _any_
message with the appropriate arguments (message and field value)
determined at run-time (by the user).

Argh, I thought Ada would be a blessing. That old C construct 'void *'
should have been handy...
...

>> I would love to make Put dispatching but how would a procedure look
>> like that can assign a value to any field in a record?

>Variant 1. Derive all values from one base

>  type Message_Value is abstract tagged ... or Controlled

How would that make Put dispatching? Note that the Message is a fixed
record, whose fields (one or more) I want to assign one or more values
to (not known at compile time etc etc).

>Variant 2. Use streams. Your record will be a stream (derived from
>Ada.Streams.Root_Stream_Type). For each type there are attributes
'Input
>and 'Output. See ARM 13.13.

That's new stuff to me, have to check it out.

...

>>>> There will also be a nice general mechanism that basically gets
any
>>>> type of message, applies any actions enqueued for it and then puts
the
>>>> message away. It feels like this should be possible with Ada
mechanisms
>>>> such as inheritage, polymorphy and generics but, I kind of doubt
it
>>>> now...
>>>It is definitely possible:
>>>package Messages is
>>> type Message is
>>>     abstract new Ada.Finalization.Limited_Controlled with private;
>>> procedure Execute (This : in out Message) is abstract;

>>> type Messages_Queue is
>>>     [abstract] new Ada.Finalization.Limited_Controlled with
private;
>>> -- Abstract if there should be different implementations of queues
>>> procedure Enqueue
>>>     (  Queue : in out Messages_Queue;
>>>        Item : in out Message'Class
>>>     )  [is abstract];
>>>private
>>> ...
>>>end Messages;

>>>package Messages.My_Messages is
>>>  type My_Message is new Message with private;
>>>  procedure Finalize (This : in out Message); -- How to destruct
>>>  procedure Initialize (This : in out Message); -- How to construct
>>>  procedure Execute (This : in out Message); -- What to be done
>>>  procedure Put_A (This : in out Message; A : Something);
>>> ...

>> Ugh, I don't get it.

>> How could the message know what to do in Execute? There may be 0 or
5
>> or 500 actions to be taken on each message.

>Ok, then replace "Message" with "Action" and make Message an Action
>container.

This doesn't make sense to me (probably due to that I haven't
understood your idea).

My gut tells my that Messages should not "contain" Actions or vice
versa.

They are separate structures that should interract but not
"contaminate" each other.

Messages are separate from Actions, have separate lives and flow in the
system. Actions (may) appear in one part of the system and should be
"performed on" or "applied to" Messages, but not "owned by" or
"contained within" the Messages.

Message instances are created, routed and destroyed (sort of)
dynamically.
Actions are sitting in their queues waiting for the right moment
(user-defined time) to Execute. At that time a certain Message instance
exist on which type the Action is programmed to Execute upon. It
Executes (in this case overwrites a field in the message record with a
user-defined value), then the Action is destroyed. The Message is
passed on to other adventures (such as being acted upon by other
Actions)

The life time of Messages and Actions are hence fundamentally
different. I'm afraid we don't understand eachother. Probably due to
that I, being an Ada newbie, try to grasp too much at one time and also
fail in explaining the problem.

>The difference in the expected type. Print expects a message,
>OverrideMethodRefType expects MessageType. Those are different types.
The
>compiler does not know about your intention to substitute message for
>MessageType. Because, next day, you might change your mind and
substitute
>Boolean instead.

OK, I can see that now.




  reply	other threads:[~2005-01-03 12:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-22 13:49 OO problem: Performing actions on messages (very long, sorry) per
2004-12-22 15:17 ` Dmitry A. Kazakov
2004-12-22 16:28 ` Martin Krischik
2004-12-22 17:42   ` per
2004-12-22 18:16     ` Martin Krischik
2004-12-22 19:54     ` Dmitry A. Kazakov
2005-01-03 12:37       ` per [this message]
2005-01-03 14:14         ` Dmitry A. Kazakov
2005-01-04 12:05           ` per
2005-01-04 13:30             ` Dmitry A. Kazakov
2005-01-04 15:21               ` per
2005-01-04 17:47                 ` Dmitry A. Kazakov
2005-01-05 12:01                   ` per
2005-01-05 13:23                     ` Dmitry A. Kazakov
2005-01-05 15:59                       ` per
2005-01-05 20:44                         ` Dmitry A. Kazakov
2005-01-10  8:42                           ` per
2005-01-10 14:22                             ` Dmitry A. Kazakov
2005-01-10 16:24                               ` per
2005-01-10 19:09                                 ` Dmitry A. Kazakov
2005-01-11  9:06                                   ` per
2004-12-22 17:46   ` per
2004-12-22 18:02     ` Martin Krischik
2005-01-03 10:05       ` per
2004-12-22 18:35     ` u_int32_t
2004-12-22 18:38       ` u_int32_t
2004-12-24 18:52 ` Nick Roberts
2005-01-03 16:59   ` per
2005-01-10 12:10   ` per
2005-01-10 13:49     ` Marius Amado Alves
2005-01-10 21:54 ` Simon Wright
replies disabled

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