My Friend and I have this debate about it is faster in AS3 to pass this to another object to be able to have communication/interaction between the two or if Events are the way to go. While using Events to accomplish this task is pretty standard, here is some dummy code to illustrate the question:
public class ClassA{
public var items:Array = new Array();
public function classA(){
items.push(new ClassB(this));
}
public function poke(){
trace('yes, can i help you?');
this.items.speak();
}
}
public class ClassB{
public var parentObject:Object;
public function classB(pobj:Object){
parentobject = pobj;
parentobject.poke();
}
public function speak(pobj:Object){
trace('nothing, forget it!');
}
}
So if ClassA gets constructed it will push a new object of ClassB into its items-Array. ClassB's constructor calls the Class-A instance's poke() which immediatly calls the ClassB's speak()-function.
I don't what the correct term for this method is (or if there is even is one). My friend says he feels his code runs faster when using many objects but I doubt it because I think this might confuse the Garbage Collector.
What are your thoughts on this topic and what sources would you recommend to read on this topic?