Hi Jethani,

I guess this would be the only proper way... Too bad I can't check it
@compile time, but I guess that makes sense ...

I'm going to go with you and do a little loop in the analyze() method and
check all the items (or part of them) against the interfaces.

Thanks for thinking with me

On Sun, Mar 23, 2008 at 7:27 AM, Manish Jethani <[EMAIL PROTECTED]>
wrote:

>   On 3/23/08, Jeroen Beckers <[EMAIL PROTECTED]<thedauntless%40gmail.com>>
> 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?
>  
>

Reply via email to