<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label id="lb" text="check"/>
<mx:Script>
<![CDATA[
import mx.managers.BrowserManager;
import mx.managers.IBrowserManager;
public var brm:IBrowserManager = BrowserManager.getInstance();
]]>
</mx:Script>
</mx:WindowedApplication>
In the above code, IBrowserManager is an interface, and BrowserManager.getInstance()
returns an object of type IBrowserManager. But, from whatever I know of interfaces,
one can’t create an instance of an Interface? So, how come can I create an instance
of an interface here?
Let’s say you had an interface, IPerson, that defined two members — name and gender:
… and you had two concrete classes, Woman and Man, both of which implemented the IPerson interface.
and
You could then ultimately do something like this:
… which is to say, act on (in this case, trace the properties of) the concrete implementations of Man and Woman as though they were the same kind of object, since they both conform to the IPerson interface (i.e., the both define name and gender properties).
It’s the object-oriented principle of polymorphism at work — sometimes you’ll hear it as the tenet, “Program to interfaces, not implementations.” Hope that helps!