comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: OO problem: Performing actions on messages (very long, sorry)
Date: Mon, 3 Jan 2005 15:14:14 +0100
Date: 2005-01-03T15:14:14+01:00	[thread overview]
Message-ID: <8oknh024yb43$.71qlyp6g8y2x$.dlg@40tude.net> (raw)
In-Reply-To: 1104755823.837077.74630@z14g2000cwz.googlegroups.com

On 3 Jan 2005 04:37:03 -0800, per wrote:

>>> 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)

Neither it knows that M1 has Put. Again there is no difference.

> 2. Action should cope with any Message (M1, M2, etc).

So they have to have something in common. What? The name "Put"? It is too
little and as good as ":=". 

> 3. Action should cope with any type of the field to overwrite.

What is known about *any* type? Nothing. So what can action do with that?
Also nothing.

> 4. The value to overwrite _with_ is determined at run-time (by the user).

Value or type. It is a great difference. A value determined at run-time?
Here:

   I : Integer;
begin
   I := <determinied at run-time value>;

A type determined at run-time? That is either class-wide or variant record.

> 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).

Appropriate arguments constitute no language entity. Specific Put means
that Put is polymorphic. It means that there is *one* Put, implemented by
many specific overridings of Put according to the concrete type of a
polymorphic (class-wide) parameter. But it is *one* Put, with *one*
parameter profile, of *one* root type.

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

Observe that void * is a type. Exactly one type. You cannot achieve what
you describe with void *. It is rather C++'s ellipsis ".." what you are
talking about. But neither ".." nor "void *" arguments cannot be
dispatching. You have to bring *all* possible variants under one roof.
There are many ways to do it. 

>>> 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).

type Message_Value is abstract tagged;
procedure Put (Action : Action_Type'Class, Value : Message_Value);
   -- This dispatches on Value

>>> 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.

Who determines what action to apply? Above you talked about actions dealing
with polymorphic messages. That means that the message type (its type tag
buried in a class-wide value) determines the action. Is that correct? If
yes, then definitely actions are just methods of Message. What is Execute
then?

> 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)

So message is a polymorphic value. This is the variant 1. If message may
contain more than one value then it is a container of Message_Value.

> 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.

Try to explain it in C++ terms. Draw a class diagram. What are
relationships between Message, Action, Execute?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-01-03 14:14 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
2005-01-03 14:14         ` Dmitry A. Kazakov [this message]
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