From: "per" <commander@death-star.com>
Subject: Re: OO problem: Performing actions on messages (very long, sorry)
Date: 3 Jan 2005 08:59:21 -0800
Date: 2005-01-03T08:59:21-08:00 [thread overview]
Message-ID: <1104771561.230528.42530@c13g2000cwb.googlegroups.com> (raw)
In-Reply-To: gemini.i98prk00kdjon02hs.nick.roberts@acm.org
Nick:
>From what I can gather about the design you are looking for, my
impression
>is that you need two tagged types -- one for messages, one for actions
--
>and a mechanism of 'multiple dispatch' to select the appropriate Put
>procedure.
Thanks for joining in Nick.
Yes, I believe your impression is right! Unfortunately my problem lies
a little deeper than that I think...
>Some languages support a form of method selection called 'multiple
>selection', where a method can be selected depending on the type of
not >just
>one but several parameters. Multiple dispatch is the workmanlike way
that
>you do the equivalent of multiple selection in languages that don't
>support
>it (such as Ada). The essence is that first you dispatch selecting on
one
>kind of tagged type (in this case, a message), into a procedure that
then
>itself dispatches selecting on another tagged type (in this case, an
>action), and possibly so on for yet more parameters.
OK, I get the idea and it could be half-way to what I want.
I just have to add that I (and probably you too) really dislike that
kind of "manual dispatching" for obvious reasons (maintenance, risk of
error, the volume of work if there are lots of Actions/Messages, etc).
>I'll try to illustrate this idea.
You did!
Actually Nick, parts of your example is very similar to my code!
There are some things I don't think will work in my system (such as
letting the Actions reside in queues _inside_ a Message, see my post
above), but let's leave that for the moment...
> procedure Execute (M: in out Stock_Despatch_Message;
> A: in Action'Class) is
My declaration of procedure "Execute" (declared for each Action
package):
procedure Execute(Self : in out Instance;
M : in Message.Class_Reference);
is very similar to your.
Rewritten to
procedure Execute(Self : in out Instance;
M : in Message.Instance'Class);
it is almost identical. I have switched the "dispatching order" since I
want to do Execute on an Action and not a Message (and my design
currently is that way), but in principle that doesn't matter, right?
If I modify the body of Action.Override.Execute to something like this:
procedure Execute(Self : in out Instance;
M : in Message.Instance'Class) is
begin
-- Message.Print(M.all);
if M in Message.M1.Instance'Class then
...
elsif M in Message.M2.Instance'Class then
...
elsif M in <and so on...>
...
end;
end;
I have your manual dispatching, right? So far so good.
Now to the actual problem:
What should I write in the if-clauses?
One "obvious" variant is:
if M in Message.M1.Instance'Class then
Self.OverrideMethodRef(Message.M1.Instance(M), Self.Argument);
...
(This is supposed to include an explicit type conversion from
Message.Instance'Class to Message.M1.Instance.)
But that won't compile since the compiler expects MessageType (generic
parameter) but gets Message.M1.Instance.
(Self.OverrideMethodRef is a procedure-access to a Put_ procedure with
a specific message and a value as parameter.)
And this is the very same problem I had from the beginning! :(
>Please study the code I've written carefully. However, I've not tested
it >in
>any way, so it's likely to have some faults! I'm hoping that I've got
>close
>here to providing a design that will be of genuine use to you, Per. If
>not,
>please say! You will probably have a lot of questions, but that's fine
by
>me.
I think I've got your point, although I still have problems as you see.
Do you have any further ideas?
next prev parent reply other threads:[~2005-01-03 16:59 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
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 [this message]
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