Interfaces can do much more than just help multiple coders stay on
track. In Actionscript 3, they can be used to mimic multiple
inheritance, decrease file size of loaded swfs, and clarify your own code.
Interfaces are simple, but understanding Interfaces and how and when to
use them takes a bit more time. You need a firmly established
understanding of core OOP concepts like inheritance, abstract/concrete,
and factories. Once you fully understand those, the transition into
learning how interfaces work will be a lot easier and will pave the way
for the "Ah ha!" moment when you actually "get" how they benefit you.
If you're the only person working on a project, interfaces can be less
useful unless you know how to use them well. Putting them in just to
put them in serves no purpose other than bloating your code. But,
sometimes you need to do that in order to figure them out.
For instance, let's say you have multiple swfs, and some class and its
inheritance chain is fairly large when compiled. Rather than import the
Abstract class type in the loaded swfs, you can instead import the
Interface for the class and your loaded swf won't need to know the inner
workings of any class that follows the interface to compile. At
runtime, the class will exist because the main movie loaded it, and all
the loaded swf needs to know is that if it calls a particular method of
an interface, it's guaranteed to be in the class because the class
follows that interface. That's just one example of how interfaces can
be used.
If you want to see some example code for interfaces, install my Gaia
Framework, create a new AS3 project, and take a look at the
com.gaiaframework.api package. There are interfaces for all of the
asset classes, as well as the the main Gaia API. There are more
complicated uses for interfaces, such as multiple inheritance, but best
to learn the basics before you jump into that aspect.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders