Let's say you had an interface, IPerson, that defined two members -- name and gender:
public interface IPerson
{
function get name():String;
function set name(value:String):void;
function get gender:String;
function set gender(value:String):void;
}
... and you had two concrete classes, Woman and Man, both of which implemented the IPerson interface.
public class Man implements IPerson
{
private var _name:String;
private var _gender:String;
public function Man(name:String, gender:String)
{
this.name = name;
this.gender = gender;
}
public function get name():String
{
return _name;
}
public function set name(value:String):void
{
_name = value;
}
public function get gender()
{
return _gender;
}
public function set gender(value:String):void
{
_gender = value;
}
}
and
public class Woman implements IPerson
{
private var _name:String;
private var _gender:String;
public function Woman(name:String, gender:String)
{
this.name = name;
this.gender = gender;
}
public function get name():String
{
return _name;
}
public function set name(value:String):void
{
_name = value;
}
public function get gender()
{
return _gender;
}
public function set gender(value:String):void
{
_gender = value;
}
}
You could then ultimately do something like this:
var crowdOfPeople:ArrayCollection = YourCrowdOfPeopleClass.getInstance();
for each (var p:IPerson in crowdOfPeople)
{
trace(p.name);
trace(p.gender);
}
... 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!