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.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,19d0849c68914783 X-Google-Attributes: gid103376,public From: Thom Brooke Subject: Re: Design problem using Multiple Dispatch or Redispatch (long) Date: 2000/03/15 Message-ID: <38CEF549.90AD0C67@yahoo.com>#1/1 X-Deja-AN: 597620004 Content-Transfer-Encoding: 7bit References: <38CDAA56.36B9E1C1@yahoo.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 953087513 158.252.164.50 (Tue, 14 Mar 2000 18:31:53 PST) Organization: EarthLink Inc. -- http://www.EarthLink.net MIME-Version: 1.0 NNTP-Posting-Date: Tue, 14 Mar 2000 18:31:53 PST Newsgroups: comp.lang.ada Date: 2000-03-15T00:00:00+00:00 List-Id: Hmmm. I tried something like this, and ran into the following problem: I couldn't avoid duplicate code to construct the Real_Commands for the different processors. Consider a command that has three fields: ID, Number, and Version. And two kinds of Processors. I would do this, right? with Commands; with Processors; package Real_Processor1 is type Processor1 is new Processors.Processor with private; type Command1 (For_The : access Processor1) is new Commands.Command with private; procedure Handle (The_Command : Command1); -- and I added this as a new primitive abstract operation: procedure Construct (The_Command : in out Command1; From : in Byte_Stream); private type Processor1 is new Processors.Processor with ... type Command1 (For_The : access Processor1) is new Commands.Command with record ID : Natural; Number : Integer; Version : Positive; end record; end Real_Processor1; -- same thing for Real_Processor2 So the problem is, how can I write the "Construct" procedure one time (the resulting Commands will look identical, and they come from identical byte streams. The only difference is one is of type Real_Processor1.Command1, and the other is of the completely different, but structurally identical type Real_Processor2.Command1)? Am I missing something obvious? -- Thom Simon Wright wrote: > > The code below may do what you want. There will be lots more (creating > new Real_Commands, for example, for a specific Processor; keeping a > queue of Commands, popping, and dispatching; and, because Command is > (has to be) limited, you'll need to manage allocated Commands as > well). > > No need for arrays, sparse or otherwise. > > package Commands is > type Command is abstract tagged limited private; > type Command_P is access all Command'Class; > procedure Handle (The_Command : Command) is abstract; > private > type Command is abstract tagged limited null record; > end Commands; > > package Processors is > type Processor is abstract tagged limited private; > private > type Processor is abstract tagged limited null record; > end Processors; > > with Commands; > with Processors; > package Real_Processors is > type Real_Processor is new Processors.Processor with private; > type Real_Command (For_The_Processor : access Real_Processor) > is new Commands.Command with private; > procedure Handle (The_Command : Real_Command); > -- other Real_Commands here, each with its own Handle > private > type Real_Processor is new Processors.Processor > with null record; > type Real_Command (For_The_Processor : access Real_Processor) > is new Commands.Command with null record; > end Real_Processors; > > package body Real_Processors is > procedure Handle (The_Command : Real_Command) is > The_Processor : Real_Processor renames The_Command.For_The_Processor.all; > begin > null; -- do stuff for this Command for this Processor > end Handle; > end Real_Processors; -- -- Thom Brooke -- Cut out "_CUT_OUT" to get my real email address.