From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a8d137db7a5f6c81 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!c13g2000cwb.googlegroups.com!not-for-mail From: "per" Newsgroups: comp.lang.ada Subject: Re: OO problem: Performing actions on messages (very long, sorry) Date: 3 Jan 2005 08:59:21 -0800 Organization: http://groups.google.com Message-ID: <1104771561.230528.42530@c13g2000cwb.googlegroups.com> References: <1103723394.299024.314670@c13g2000cwb.googlegroups.com> NNTP-Posting-Host: 138.14.239.132 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104771567 19485 127.0.0.1 (3 Jan 2005 16:59:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Jan 2005 16:59:27 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: c13g2000cwb.googlegroups.com; posting-host=138.14.239.132; posting-account=e84-wQ0AAADeDLnjH5yWqnRMVsJLfQJg Xref: g2news1.google.com comp.lang.ada:7411 Date: 2005-01-03T08:59:21-08:00 List-Id: 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 ... 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?