View comments | RSS feed

10.2.1 Visibility of interface methods

Interface methods are visible when referenced through a property of the corresponding interface type or through a reference to the implementing class or subclass.

var a : A = new A
a.f()     // okay, f is visible through an A as {public}::f
a.g()     // okay, g is visible through an A as {public}::g
var i : I = b
i.f()     // okay, f is still visible through an I as {I}::f
i.g()     // error, g is not visible through an I as {I}::g

References through an object with an interface type are multinames that contain only the names qualified by the interface namespace and its super interface namespaces. This means that the names in the open namespaces (including public) will not be visible through a reference with an interface-typed base object. The motivation for this behavior is to express the idea of the interface as a contract between the producer and consumer of an object, with the contract specified by the names in the interface namespace alone.

If the compile-time type of the base object is not an interface type, an unqualified reference will use the currently open namespaces (which includes public) to create a multiname in the normal way. Again, ambiguous references can be explicitly qualified with the interface name to avoid conflicts.


Comments


Joe@emeraldforest said on Feb 26, 2008 at 3:00 PM :
I think this example would be understandable if we could see the definition of the class and interfaces...

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification98.html