>> 1) What's the difference between Java and AS3 getters and setters?
> One's written in Java and the other isn't ?
Extra credit for that one.  Obviously the question only applies to
interviewees with a Java background, but it illustrates an interesting
feature of Flex.

In Java, getter and setter methods have to be explicitly called. 
While in AS3, they're called automatically and externally
indistinguishable from public properties.

For instance trace(myClass.foo) might be referencing a public property
 or it might be referencing the method "public get foo():Object".  It
makes no difference to an external class.

---
You can expand on this a bit more to describe why this is useful.  The
implications are that, unlike in Java, all variables in a class are
generally public.  Java standard practices are to create only public
getters and setters while keeping the variables private.  The reason
for only allowing methods to be publicly accessible is so that 1) they
can be overridden and 2) their implementation can change without
altering class interface.

AS3 addresses both of these concerns because, as described above, a
public property can be replaced with a getter and setter without
changing the interface.  And an inherited public property can actually
be overridden by a subclass.

For example, this is valid:
public class A
{
   public var foo:Object;
}

public class B extends A
{
   override public function get foo():Object{return 'bar'};
   override public function set foo(value:Object):void{};
}


-Nick Matelli
Amentra, Inc

--- In [email protected], "Paul Andrews" <[EMAIL PROTECTED]> wrote:
>
> ----- Original Message ----- 
> From: "Tom Chiverton" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Friday, February 08, 2008 10:14 AM
> Subject: Re: [flexcoders] Re: Flex Interview Questions
> 
> 
> > On Thursday 07 Feb 2008, Uber_Nick wrote:
> >> 1) What's the difference between Java and AS3 getters and setters?
> >

> 
> My java is rather old school, but my getters and setters are explicitly 
> coded methods rather than generated for me as in AS3.
> 
> Here is an old (but fun) article: 
> http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html
> 
> Paul
> 
> 
> > -- 
> > Tom Chiverton
> > Helping to simultaneously bully collaborative infomediaries
> > on: http://thefalken.livejournal.com
>


Reply via email to