[flexcoders] best practice to handle overloading in AS3?

2009-05-28 Thread gwangdesign
Hi,

I am trying to overload a method (same name and different signatures)in a 
subclass. In the inherited class, the method looks like this:

  public function set dataProvider(value:Array):void

In my subclass I want the method to look like this:

  public function set dataProviderr(v:Object):void

So that I can handle different types.

I understand AS3 doesn't support overloading. What would be the smart way(s) to 
handle this?

Thanks.

geng 



Re: [flexcoders] best practice to handle overloading in AS3?

2009-05-28 Thread Pedro Sena
If you want the same method name in a subclass, we are talking about
override, not overload.

Flex 'deals with overload' making the arguments optionals, example:

public function test(obj:Object = null):void

then you can invoke it using test() or test(object).

Appears that you are trying to override parent's function but changing it
signature, that is not possible.

If you want to have in the same class, in the same function, receive two
different parameters, you can:

public function set dataProviderr(v:Object = null, a:Array = null):void

Then you can put the argument that you want, leaving the another one as null

or you can

public function set dataProviderr(v:*):void

This way you can pass anything you like.

Both solutions are ugly, IMHO, but is the way flex works.

HTH,

PS

On Thu, May 28, 2009 at 6:58 PM, gwangdesign gwangdes...@yahoo.com wrote:



 Hi,

 I am trying to overload a method (same name and different signatures)in a
 subclass. In the inherited class, the method looks like this:

 public function set dataProvider(value:Array):void

 In my subclass I want the method to look like this:

 public function set dataProviderr(v:Object):void

 So that I can handle different types.

 I understand AS3 doesn't support overloading. What would be the smart
 way(s) to handle this?

 Thanks.

 geng

  




-- 
/**
* Pedro Sena
* Systems Architect
* Sun Certified Java Programmer
* Sun Certified Web Component Developer
*/