There are two ways I can think of to do this. One would be to have multiple factory functions, one for each type of object you want to create. The other would be to create a simple class (FactoryParams or something like that) which stores all the parameters. You pass that as the parameter object, and you can have that parameter object be strongly typed.
class FactoryParams { public var firstParam:String; public var secondParam:Number; public var thirdParam:SomeComplexObject } By using a class instead of a generic object you can keep the type information (and if you use getters/setters instead of public variables then you can even do validation on the values if you want). -Andy On 5/1/07, Listas <[EMAIL PROTECTED]> wrote:
pedr, i would prefer to use the arguments array, instead of an object, but i´m afraid this isn´t strong typed as you wish private function createItem(key:String):Void{ switch(key){ case "item_1": var wid_num:Number = arguments[1]; var y_num:Number = arguments[2]; myItem = new Item_1(wid_num, y_num); break case "item2": var hei_num:Number = arguments[1]; var color_num:Number = arguments[2]; myItem = new Item_2(hei_num, color_num); break etc... } } Ruy Adorno > Hi, > > A have a Factory that needs to instanciate Objects with differing > numbers of > parameters (1-4). Is there any way to deal with this situation and > maintain > strong typing. > > private function createItem(param_ob:Object, key:String):Void{ > switch(key){ > case "item_1": > myItem = new Item_1(param_ob.width, param_ob.y); > break > case "item2": > myItem = new Item_2(param_ob.height, param_ob.color); > break > etc... > } > } > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > > > > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
_______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com