User Guide
Interfaces 129
You do have some flexibility, however, in how you name the parameters of methods that you
implement. Although the number of parameters and the data type of each parameter in the
implemented method must match that of the interface method, the parameter names do not
need to match. For example, in the previous example the parameter of the
Alpha.foo()
method is named
param:
public function foo(param:String):String {}
But the parameter is named str in the IAlpha.foo() interface method:
function foo(str:String):String;
You also have some flexibility with default parameter values. An interface definition can
include function declarations with default parameter values. A method that implements such
a function declaration must have a default parameter value that is a member of the same data
type as the value specified in the interface definition, but the actual value does not have to
match. For example, the following code defines an interface that contains a method with a
default parameter value of 3:
interface Igamma
{
function doSomething(param:int = 3):void;
}
The following class definition implements the Igamma interface, but uses a different default
parameter value:
class Gamma implements Igamma
{
public function doSomething(param:int = 4):void {}
}
The reason for this flexibility is that the rules for implementing an interface are designed
specifically to ensure data type compatibility, and requiring identical parameter names and
default parameter values is not necessary to achieve that objective.