I hate this pattern and it’s very popular these days with as3 API’s:
{
public class AllMightyClass
{
public var _value0:String;
public var _value1:Array;
public var _value2:int;
public var _value3:Object;
public function AllMightyClass(params:Object)
{
_value0 = params.value0;
_value1 = params.value1;
_value2 = params.value2;
_value3 = params.value3;
}
}
}
// FROM OUTSIDE THIS WOULD LOOK LIKE:
var amclass:AllMightyClass = new AllMightyClass(
//editor hints: AllMightyClass(params:Object)
Is this something that people use with some other language or something they learn at school?
It’s just wrong. The end user has no idea what params it wants or what’s their type.
Why not use:
{
public class Test
{
public var value0:String;
public var value1:Array;
public var value2:int;
public var value3:Object;
public function Test(value0:String, value1:Array, value2:int, value3:Object)
{
this.value0 = value0;
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
}
}
}
// FROM OUTSIDE THIS WOULD LOOK LIKE:
var amclass:AllMightyClass = new AllMightyClass(
//editor hints: AllMightyClass(value0:String, value1:Array, value2:int, value3:Object)
You may still pass stuff to baseclass in object-format if you like and you may still check if some values are null and then turn them into default. With the first pattern API’s user need to open the class to see what parameters it swallows or even worse browse the documentation.
But there is even better way to do this:
package
{
public class AllMightyClassVO
{
public var value0:String;
public var value1:Array;
public var value2:int;
public var value3:Object;
public function AllMightyClassVO(value0:String, value1:Array, value2:int, value3:Object)
{
this.value0 = value0;
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
}
}
}
// USE THAT TO PASS YOUR PARAMETERS
package
{
public class AllMightyClass
{
public var value0:String;
public var value1:Array;
public var value2:int;
public var value3:Object;
public function AllMightyClass(valueObject:AllMightyClassVO)
{
this.value0 = valueObject.value0;
this.value1 = valueObject.value1;
this.value2 = valueObject.value2;
this.value3 = valueObject.value3;
}
}
}
// FROM OUTSIDE THIS WOULD LOOK LIKE:
var amclass:AllMightyClass = new AllMightyClass(
//editor hints: AllMightyClass(valueObject:AllMightyClassVO)
// OK IT EATS AN OBJECT CALLED AllMightyClassVO (let’s write some more)
var amclass:AllMightyClass = new AllMightyClass(new AllMightyClassVO(
//editor hints: AllMightyClassVO(value0:String, value1:Array, value2:int, value3:Object)
You can allways extend your VO class with some abstract when you want to pass it down to base classes. This way you make it look intuitive for end user.

Entirely agree. Using anonymous objects as initialization breakes code completion and is considerably slowing down the AVM2. Using VO’s might be a solution, but the goal of using anonymous objects seems to be to create less, and less “typed” code. I’ve never really gotten the purpose of this. Being more and more dependend on using advanced coding tools and code completion (it’s the “real coders use notepad” discussion all over again) these practices both negatively affect code creation and runtime speed.
Not sure if the VO’s will make the situation better, but really loved you had something to say about it…it’s time it’s noted.
It looks jQuery-ish.