"I understand what interfaces are, but I'm not entirely clear on when
they become advantageous to use.  Anyone care to shed some light?"

I find them really useful for implementing the strategy pattern, and I find
the strategy pattern to be extremely useful in Flash.

Let's say, for example, that you're implementing a number of different types
of lists.  You could:

- make an interface, IList, that declares all of the methods you think lists
will need and the arguments they will accept.

- Make a base class, List, that implements those methods.

- Create subinterfaces of IList, like IHashMap, or whatever, which override
methods and add additional methods and subclasses of List that implement
those new interfaces.

Here's why this is good:

-  You have tight coupling between all list classes.  When you know how one
works, you pretty much know how they all work.
-  If you want to make changes to all of the classes in the list package, do
so in IList.  All of the classes that implement IList will be forced to
adopt those changes.
- You get rid of a lot of conditional statements.  All of the things in the
list package you created above have at least 2 valid types: IList and their
own class type.  Let's say you have some other widget or something that
accepts lists as a dataprovider, for example.  Without this sort of
architecture, you might need branching conditionals 'if myList instanceOf
HashMap, then do this.'  But here they all share the type IList.  So you can
call common methods on them that were declared in the interfaces, and be
sure that they will produce predictable results.

All of that said, interfaces create more work.  To make them viable, you
really need an editor that supports this kind of coding.  For example, if I
change method signatures in an interface, FDT lets me know everywhere else I
need to change them.  Without FDT, I probably wouldn't use interfaces.
Also, I think they make sense when working on a framework or large project.
For simpler one-off projects, I don't use them.

For me, they are really just a way to make it easier to implement design
patterns in Flash, and especially the Strategy Pattern.  Here are a few
links:

http://en.wikipedia.org/wiki/Strategy_pattern
http://ootips.org/strategy-vs-case.html
http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/StrategyPattern.htm

Jim Kremens
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to