comp.lang.ada
 help / color / mirror / Atom feed
From: Thom Brooke <tcb_cut_out_80908@yahoo.com>
Subject: Re: Design problem using Multiple Dispatch or Redispatch (long)
Date: 2000/03/15
Date: 2000-03-15T00:00:00+00:00	[thread overview]
Message-ID: <38CEF549.90AD0C67@yahoo.com> (raw)
In-Reply-To: x7vln3l6y4t.fsf@pogner.demon.co.uk

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.




  reply	other threads:[~2000-03-15  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-14  0:00 Design problem using Multiple Dispatch or Redispatch (long) Thom Brooke
2000-03-14  0:00 ` Simon Wright
2000-03-15  0:00   ` Thom Brooke [this message]
2000-03-16  0:00     ` Simon Wright
2000-03-14  0:00 ` Nick Roberts
2000-03-15  0:00   ` Thom Brooke
2000-03-14  0:00 ` tmoran
2000-03-15  0:00   ` Thom Brooke
2000-03-14  0:00 ` David Kristola
2000-03-15  0:00   ` Thom Brooke
replies disabled

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