I pinged a internal guru on this.  Short answer is, it can't be done.  Though 
the relationship is so close between implicit and explicit mutator and 
accessor, its not that close to do this.  Best to expose via explicits in the 
base class, use the IDE tools for speed.  As for building a public SWC with a 
class with public property you as a consumer may want to override, well, it can 
be argued that that's up to the owner to decide to expose this, its a class 
behavior.  eg, in DougsSuperCrummyVideoPlayer.as I don't want you the 
implementer to change how my public var foo behaves.  Sure, call me a 
protectionist, but that's my call :)   Of course you the implementer could 
create a explicit setter for myOwnStinkingFoo that sets super.foo as you see 
fit.  :) 

peas

Douglas Knudsen
[email protected]



On Dec 8, 2010, at 8:36 AM, Dale Bronk wrote:

> Sorry I didn’t explain well.  It really is a dead point as it can’t be done.  
> I was just wonder if anyone knew the design reason.  But anyway, here is what 
> I wanted to do…
>  
> ClassA
>                 public var level : int = 0;
>  
> ClassB extends ClassA
>                 override function get level() : int
>                 {
>                                 return 
> determineLevelBasedOnUserPermissions(super.level);
>                 }
>                 private function 
> determineLevelBasedOnUserPermissions(level:int) : int
> {
>                 // Do crazy stuff here to determine new level based on user 
> permissions
>                 // Audit if calculated level is different that level
>                 return calculatedLevel;
> }
>  
>  
> The extended class takes user permissions into account for a specific part of 
> the app.  Unfortunately the super class has level as a public var.  Been that 
> way for a long time.  With this new feature spec we need to modify in a 
> single place in the app based on user permission.
>  
> Already had the super class change to get/set so we are past it.  Better 
> solution would have been remove all access to the property and change to real 
> function to get them and let the function decide when user permission is in 
> order, but that was more refactoring than we are prepared to do right now 
> (although easy refactoring).
>  
> I was just wondering if anyone knew why.  I could see this as a problem if a 
> person was to download a non open source swc and the builders of that swc 
> didn’t put in the boilerplate get/set and instead just left the var public.  
> Bottom line is that I’ll now start putting in that dreaded boilerplate 
> get/set code in my classes that will become part of a library.
>  
> Dale
>  
> From: [email protected] [mailto:[email protected]] On Behalf Of Darin Kohles
> Sent: Tuesday, December 07, 2010 8:10 PM
> To: [email protected]
> Subject: Re: [AFFUG Discuss] Needs override, doesn't allow override
>  
> I guess perhaps I am missing then what you were trying to do? There is no 
> reason to even mention a super class public variable in a subclass 
> declaration, it is included by definition.
> 
> Class A{
> public var foo:*;
> }
> 
> Class B extends A{
> }
> 
> instanceOfA.foo = bar;
> 
> instanceOfB.foo = bar;
> 
> (instanceOfB as A).foo = bar;
> 
> (instanceOfA as B).foo = bar;
> 
> All 4 of the above statements are valid as you can cast up and down the class 
> hierarchy for any public variables. Super classes all pass through their 
> public variables to subclasses, so there is no reason to re-declare or 
> override.
> 
> so:
> 
> Class C extends B{
> }
> 
> instanceOfC.foo = bar; // the inheritance chain passes through all public 
> variables and functions.
> 
> On Tue, Dec 7, 2010 at 5:30 PM, Dale Bronk <[email protected]> wrote:
> Thanks.  I’m actually not setting to an explicit value, just left that code 
> out as it is not important to the question.  Do you know the design reason 
> for not being able to override the variable with implicit (although explicit 
> after compilation) getter/setter?
>  
> One of the things I love about ActionScript is that we are not forced to 
> create boiler plate code for getter/setter for each variable.  I come from 
> the Java world and we need to do that.  I find great power in just making the 
> property public.  Then any other class that needs to get or set can simply do 
> something like myObj.foo = bar.  If later myObj decides that the setter 
> should do something else, simply tweak the code and add the setter.  The 
> other classes code does not need to change, it still just does myObj.foo = 
> bar.  In Java, this is not the case, you’d have to do myObj.setFoo(bar).  I 
> love the fact that we don’t have to litter our code with boilerplate 
> getter/setter and only implement if we need more processing during a get or 
> set.
>  
> With the way it works with not being able to override really removes this 
> ability.  I know that we have code generators for creating getter/setters and 
> we can collapse the code in the IDE, but that still has a bunch of dumb code 
> that needs to be there.  So if you know the design reason, I’d love to know 
> what it is.
>  
> Thanks,
> Dale
>  
> From: [email protected] [mailto:[email protected]] On Behalf Of Darin Kohles
> Sent: Tuesday, December 07, 2010 4:20 PM
> To: [email protected]
> Subject: Re: [AFFUG Discuss] Needs override, doesn't allow override
>  
> Public properties have implicit getter/setter behavior, but as you found you 
> can not override an implicit function with an explicit override (yes, once 
> compiled their will be an actual explicit function if you look at the source, 
> but this doesn't help you during compilation).
> 
> If Class A is always used as a super class, have your colleague change it 
> from public to protected. If however, you really want to add custom 
> code/functionality for the retrieval of the variable that is different than 
> what is supplied by the underlying public property (in your example it looks 
> like you are trying to force it to return a set value regardless of what the 
> actual value is).
> 
> I'd suggest playing with BindingUtils (assuming the public property iAmPublic 
> is [Bindable]):
> 
> var cw:ChangeWatcher = BindingUtils.bindSetter( overrideSet, this, iAmPublic);
> 
> private function overrideSet( value:int ):void
> {
>   iAmPublic = 9;
> }
> 
> This guarantees that if the property is set, it is set to the value you want, 
> but does not guarantee that the property has a value (or in this case a 
> specific value. You can ensure the property is set by explicitly assigning a 
> vale (then overridden to your desired value) during initialization.
> 
> 
> On Tue, Dec 7, 2010 at 2:51 PM, Dale Bronk <[email protected]> wrote:
> I'm sure there is a reason for this, but I don't know it and can't seem to
> find it googling.
> 
> I have:
> 
> ClassA
>        public var iAmPublic : int = 0;
> 
> ClassB extends ClassA
>        public function get iAmPublic() : int { return 9; }
>                - or -
>        override public function get iAmPublic() : int { return 9; }
> 
> Both compile error out.  Either with I must override the function or invalid
> override.
> 
> If I change ClassA to have public function get/set ....   it will work fine.
> I realize that behind the scenes a get/set must be created for me, but it
> seems to me the compiler should be smart enough to handle this.  The big
> problem is that I'm dealing with a swc that has the property as a public var
> so I can't override it.
> 
> Anyone have any ideas?  I can go to the person and have them change it to do
> getter/setter, but doesn't this seem like something that should just work?
> 
> Thanks,
> Dale
> 
> 
> 
> -------------------------------------------------------------
> To unsubscribe from this list, simply email the list with unsubscribe in the 
> subject line
> 
> For more info, see http://www.affug.com
> Archive @ http://www.mail-archive.com/discussion%40affug.com/
> List hosted by http://www.fusionlink.com
> -------------------------------------------------------------
> 
> 
> 
> 
> -- 
> Darin Kohles
> 
> 
> -------------------------------------------------------------
> To unsubscribe from this list, simply email the list with unsubscribe in the 
> subject line 
> 
> For more info, see http://www.affug.com 
> Archive @ http://www.mail-archive.com/discussion%40affug.com/
> List hosted by FusionLink 
> -------------------------------------------------------------
> 
> 
> 
> -- 
> Darin Kohles
> 
> 
> ------------------------------------------------------------- 
> To unsubscribe from this list, simply email the list with unsubscribe in the 
> subject line 
> 
> For more info, see http://www.affug.com 
> Archive @ http://www.mail-archive.com/discussion%40affug.com/ 
> List hosted by FusionLink 
> -------------------------------------------------------------

Reply via email to