Just from first glance I'd suggest not following the design pattern of
returning the object from the function like you're doing. It seems
like the only reason you're doing it is to make it so you can write a
bunch of statements all on one line. In terms of someone else reading
your code, I think it would make a lot more sense if they saw this:

camera.move(10, 12);
camera.rotateX(45);
camera.rotateY(90);

It turns 1 line into 3 lines, but I think it's far less confusing and
this follows the same design pattern that most other Actionscript
classes follow. Methods like move, rotate, etc are used often in
various classes and usually they do what they're supposed to do and
return void. In my experience I've never really seen an OOP class that
returns itself very much.

So that's not a direct answer to your question, merely a coding
suggestion.

Doug


--- In flexcoders@yahoogroups.com, "David_Stafford"
<[EMAIL PROTECTED]> wrote:
>
> Please pardon this simple-minded question from an AS3 novice.
> 
> My base class often returns 'this' from methods which makes it 
> convenient to write code like:
> 
>   camera.move( 10, 12 ).rotateX( 45 ).rotateY( 90 );
> 
> The problem comes when code extends the base class and overrides one 
> of these functions.  The compiler insists, correctly, that the return 
> type of an overriding function must match the one in the base class.  
> What I want to do is return the 'this' object that is of the type of 
> the derived class.  Is this possible?
> 
> The following is a contrived example to demonstrate.  It won't 
> compile because the overridden function in the derived class wants to 
> return a type of MyCamera rather than Camera:
> 
> 
> public class Camera
>   {
>   var x:int = 0;
>   var y:int = 0;
> 
>   public function move( x:int, y:int ) :Camera
>     {
>     this.x += x;
>     this.y += y;
> 
>     return( this );
>     }  
>   }
> 
> public class MyCamera extends Camera
>   {
>   override public function move( x:int, y:int ) :MyCamera
>     {
>     super.move( x, y ); 
> 
>     if( x < 0 )  x = 0;
>     if( y < 0 )  y = 0;
> 
>     return( this );
>     } 
>   }
>


Reply via email to