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: "Nick Roberts" Subject: Re: Design problem using Multiple Dispatch or Redispatch (long) Date: 2000/03/14 Message-ID: <38ce8f82@eeyore.callnetuk.com>#1/1 X-Deja-AN: 597456062 References: <38CDAA56.36B9E1C1@yahoo.com> X-Original-NNTP-Posting-Host: da129d215.dialup.callnetuk.com X-Trace: 14 Mar 2000 19:14:10 GMT, da129d215.dialup.callnetuk.com X-MSMail-Priority: Normal X-Priority: 3 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Date: 2000-03-14T00:00:00+00:00 List-Id: 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