On 3/23/08, Jeroen Beckers <[EMAIL PROTECTED]> wrote: [snip] > If I want to analyze a list of items, those items must implement the correct > interface, according to which analyzers you have added to the class. Fe: > > var myClass:AnalyzerBundle = new AnalyzerBundle(); > myClass.addAnalyzer(new HeightAnalyzer()); > myClass.addAnalyzer(new LevelAnalyzer()); > myClass.analyze(new Array(item1, item2, item3)); > > What I am looking for now, is a way to make sure that item1, item2 and item3 > all implement the IHeightItem and ILevelItem interfaces. [snip]
There's no compile time way to do this. I would implement a targetInterface property as part of the IAnalyzer interface. interface IAnalyzer { function get targetInterface():Class; ... } Then, in the analyze method, I'd verify the items before passing them to the analyzers. If the verification fails, throw an error. public function analyze(list:Array):void { for each (var item:Object in list) for each (var analyzer:IAnalyzer in analyzers) if (!(item is analyzer.targetInterface)) throw new Error("&[EMAIL PROTECTED]"); ... } It also depends on whether your analyzers are supposed to be able to deal with items that don't implement their iterfaces. Can't they simply ignore those items?