<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc = "http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
	<channel rdf:about="http://livedocs.adobe.com/">
	<title>LiveDocs Comments - flash - 9.0 - main - 00000067.html</title>	
		<link>http://livedocs.adobe.com/</link>
		<description>Macromedia LiveDocs - online documentation with user feedback.</description>
		<copyright>Copyright 2009, Macromedia, Inc.</copyright>
		<dc:date>2009-11-26T03:17:12</dc:date>
		<dc:language>en-us</dc:language>
		<items>
			<rdf:Seq>
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/main/00000067.html#79413" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76731" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76709" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76684" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76624" />
			</rdf:Seq>
		</items>
	</channel>
	
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/main/00000067.html#79413">
		<title>flash/9.0/main/00000067.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/main/00000067.html#79413</link>
		<description>Also, correct me if I'm wrong, interfaces can be intregal in downcasting - which is comparing two different object types that share the same interface.  For example, if you have object type foo and object type bar, and if they both implement the same Interface, you can compare the two objects.</description>
		<dc:creator>bobw2829</dc:creator>
		<dc:type>0 0</dc:type>
		<dc:date>2008-01-11T10:52:30</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76731">
		<title>flash/9.0/main/00000067.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/main/00000067.html#76731</link>
		<description>@petkusj:&lt;br&gt;&lt;br&gt;Yes, for most of the programming that most people will be doing, you won't need to create interfaces. The most common case where you'd create an interface is if you're creating a class library or framework that is designed for other developers to use. Another common use of interfaces is if you're using what are called &quot;design patterns&quot; -- which are essentially strategies for structuring applications to solve specific programming problems.&lt;br&gt;&lt;br&gt;And yes, it'll be more common for you to be extending classes and/or implementing interfaces...and if you're writing a class that implements an interface, there's a good chance that in that class you're also extending another class (as in the example I gave).&lt;br&gt;&lt;br&gt;The good news is that, if the library/framework is designed well, you can often make use of the default implementation (if there is one) to help you implement the interface. For instance, if I'm writing a class that implements IEventDispatcher because I can't extend EventDispatcher, I can still create and use an EventDispatcher internally in my class as a &quot;helper&quot;, so that I don't have to recreate the functionality that's already built into EventDispatcher. Here's a minimal example of an IEventDispatcher that uses EventDispatcher internally to do its work (a common way to say this is that you &quot;incorporate the class using 'composition' rather than 'inheritance'&quot;). It definitely requires more code than just extending EventDispatcher, but the good news is that the code can be identical for any IEventDispatcher that includes an EventDispatcher by composition, and as you can see all the work is really done by the EventDispatcher instance that's included in the class:&lt;br&gt;&lt;br&gt;package&lt;br&gt;{&lt;br&gt;	import flash.events.EventDispatcher;&lt;br&gt;	import flash.events.IEventDispatcher;&lt;br&gt;	&lt;br&gt;	public class MyClass extends MyNonEventClass implements IEventDispatcher&lt;br&gt;	{&lt;br&gt;		//&lt;br&gt;		// IEventDispatcher implementation&lt;br&gt;		//&lt;br&gt;		private var _eventDispatcher:EventDispatcher;&lt;br&gt;		&lt;br&gt;		public function MyClass()&lt;br&gt;		{&lt;br&gt;			_eventDispatcher = new EventDispatcher(this);&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void&lt;br&gt;		{&lt;br&gt;			_eventDispatcher.addEventListener(type, listener, useCapture, priority);&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		public function dispatchEvent(event:Event):Boolean&lt;br&gt;		{&lt;br&gt;			return _eventDispatcher.dispatchEvent(event);&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		public function hasEventListener(type:String):Boolean&lt;br&gt;		{&lt;br&gt;			return _eventDispatcher.hasEventListener(type);&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void&lt;br&gt;		{&lt;br&gt;			_eventDispatcher.removeEventListener(type, listener, useCapture);&lt;br&gt;		}&lt;br&gt;		&lt;br&gt;		public function willTrigger(type:String):Boolean&lt;br&gt;		{&lt;br&gt;			return _eventDispatcher.willTrigger(type);&lt;br&gt;		}&lt;br&gt;	}&lt;br&gt;}</description>
		<dc:creator>adbe_paul</dc:creator>
		<dc:type>1 0</dc:type>
		<dc:date>2007-11-15T15:09:44</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76709">
		<title>flash/9.0/main/00000067.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/main/00000067.html#76709</link>
		<description>Thanks, adbe_paul. When you say:&lt;br /&gt;&lt;br /&gt;In that case, if there was no IEventDispatcher interface and only an &lt;br /&gt;EventDispatcher class, you would have to choose to either 1) not use the &lt;br /&gt;built-in event handling mechanisms for the class, or 2) not be able to make &lt;br /&gt;the class a MyNonEventClass subclass (and hence wouldn't be able to use &lt;br /&gt;it for it's intended purpose).&lt;br /&gt;&lt;br /&gt;You're kind of saying I get to eat my cake and have it too.&lt;br /&gt;&lt;br /&gt;It seems to me, however, that for most of the programming I will be doing, I &lt;br /&gt;probably won't need to create interfaces. But I may often be extending or &lt;br /&gt;implementing interfaces. In your example, it seems I would be both &lt;br /&gt;extending AND implementing an interface?&lt;br /&gt;&lt;br /&gt;Jennifer&lt;br /&gt;&lt;br /&gt;PS I think I answered my own question.</description>
		<dc:creator>petkusj</dc:creator>
		<dc:type>0 0</dc:type>
		<dc:date>2007-11-15T09:51:54</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76684">
		<title>flash/9.0/main/00000067.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/main/00000067.html#76684</link>
		<description>@petkusj (Jennifer)&lt;br&gt;&lt;br&gt;You're absolutely right that an interface only makes sense when it's used by more than one class. Specifically, an interface is useful when you're writing code that other developers are going to be using, or that you will be using in a future time for a purpose that you might not be able to anticipate. The idea behind using an interface is to make the code flexible.&lt;br&gt;&lt;br&gt;Often, as you've noted, a library of code (such as the ActionScript core classes) includes an interface, and also includes one class that implements the interface (often referred to as the &quot;default&quot; implementation). The idea is that for most needs, the default implementation will be sufficient/useable, but in case it's not a developer can create their own class that implements the interface, and can still use it in place of the default implementation.&lt;br&gt;&lt;br&gt;For a concrete example, consider the IEventDispatcher interface and the EventDispatcher class. Every class that will be part of the ActionScript 3.0 event model must implement the IEventDispatcher interface, because there are places in ActionScript where IEventDispatcher is used as the data type of a property or a method parameter, and objects that dispatch events must be able to be used in those cases. In the vast majority of cases, if you want to create a class that will dispatch events, you can make that class a subclass of EventDispatcher, and the class inherits all the functionality it needs for dispatching events.&lt;br&gt;&lt;br&gt;What happens, however, if you are creating a class that will dispatch events (we'll call it &quot;MyClass&quot;) and you *also* need the class to expose some other functionality that's part of a different (non-EventDispatcher) class; for instance, imagine you need to be able to assign MyClass instances to a property whose data type is a non-EventDispatcher class (e.g. MyNonEventClass). In that case, in order to assign MyClass instances to that property, MyClass would have to be a MyNonEventClass subclass.&lt;br&gt;&lt;br&gt;In that case, if there was no IEventDispatcher interface and only an EventDispatcher class, you would have to choose to either 1) not use the built-in event handling mechanisms for the class, or 2) not be able to make the class a MyNonEventClass subclass (and hence wouldn't be able to use it for it's intended purpose).&lt;br&gt;&lt;br&gt;As it is, however, you could make MyClass be a MyNonEventClass subclass, *and* implement the IEventDispatcher interface, and by doing so you can use the class in both situations (in the built-in event handling framework, and in the places where you need a MyNonEventClass instance).&lt;br&gt;&lt;br&gt;As I said, in the vast majority of cases you'd just make your class an EventDispatcher subclass, and that's all that you need. But in those cases where you can't, it's sure handy to have that IEventDispatcher interface. (For a real-world example, once I was creating a flash.utils.Proxy subclass, but I wanted to be able to dispatch events as well. Since Proxy isn't an EventDispatcher subclass, I had to implement IEventDispatcher.)&lt;br&gt;&lt;br&gt;Sorry this is so long, and hopefully it is helpful.</description>
		<dc:creator>adbe_paul</dc:creator>
		<dc:type>1 0</dc:type>
		<dc:date>2007-11-14T16:49:11</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/main/00000067.html#76624">
		<title>flash/9.0/main/00000067.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/main/00000067.html#76624</link>
		<description>What's the purpose behind the interface? All it really seems to do is keep &lt;br /&gt;me one step removed from manipulating the properties of a class. I &lt;br /&gt;understand that a class can implement more than one interface and &lt;br /&gt;several classes can implement the same interface and I guess I see how &lt;br /&gt;that might be useful, but most of the interface names I've seen appear to &lt;br /&gt;be pretty specific: IEventDispatcher seems inextricably linked to &lt;br /&gt;EventDispatcher and ICellRenderer to CellRenderer. Does Flash compile &lt;br /&gt;faster because an interface was created? It certainly doesn't seem any &lt;br /&gt;easier to use.&lt;br /&gt;&lt;br /&gt;Am I correct in thinking that an interface only makes sense when it is used &lt;br /&gt;by more than one class? That it would be pointless to make an interface &lt;br /&gt;for only one class?&lt;br /&gt;&lt;br /&gt;Jennifer</description>
		<dc:creator>petkusj</dc:creator>
		<dc:type>0 0</dc:type>
		<dc:date>2007-11-13T17:29:11</dc:date>
	</item>
	</rdf:RDF>

