comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@callnetuk.com>
Subject: Re: Design problem using Multiple Dispatch or Redispatch (long)
Date: 2000/03/14
Date: 2000-03-14T00:00:00+00:00	[thread overview]
Message-ID: <38ce8f82@eeyore.callnetuk.com> (raw)
In-Reply-To: 38CDAA56.36B9E1C1@yahoo.com

First, you define an access-to-procedure type as follows:

    type Command_Executor is procedure (Command: Root_Command_Type'Class;
                                            Processor:
Root_Processor_Type'Class);

Now - and this is the key bit - you define two types which classify your
commands and processors:

    type Command_Category is (...);
    type Processor_Category is (...);

And functions that will categorise a command or processor:

    function Category (Command: in Root_Command_Type) return
Command_Category;
    function Category (Processor: in Root_Processor_Type) return
Processor_Category;

Now you declare an array which relates categories to executors:

    Executor: constant array (Command_Category,
                                        Processor_Category) of
Command_Executor :=
        (Elbow_Bending =>
            Teenagers => Execute_Bend_Elbow_On_Teenager'Access,
            Twentysomethings =>
Execute_Bend_Elbow_On_Twentysomething'Access,
            ...
            Ancient_Crinklies => null);
         ...);

Null access values are used to indicate which kinds of command cannot be
executed by which kinds of processor. Note how commands and processors can
be added without necessarily having to change this lookup table (provided
they fit into existing categories). I've made the array constant, so the
addition of a new category could prompt substantial recompilation: if this
might be a problem, you might want to consider using a variable table, with
some kind of dynamic 'registration' method for populating it.

--
Nick Roberts
http://www.adapower.com/lab/adaos







  parent reply	other threads:[~2000-03-14  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
2000-03-16  0:00     ` Simon Wright
2000-03-14  0:00 ` Nick Roberts [this message]
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