inheriting statics

Jeff Dyer jodyer at adobe.com
Tue Jan 9 09:55:28 PST 2007


The argument against inheriting statics is one for simplicity. A class
defines a factory and the type of instances created by that factory. The
class objects (the factories, not the instances) of different classes
have unrelated types and purposes, even if the instance types they
introduce are subtypes. Class statics are a simple convenience for
sharing state that is somehow associated with the meaning of a
particular class. Aliasing them through other class objects could lead
to annoying name conflicts and obscure their otherwise clear meaning.

Jd
 
> -----Original Message-----
> From: Peter Hall [mailto:peterjoel at gmail.com]
> Sent: Tuesday, January 09, 2007 9:15 AM
> To: Jeff Dyer
> Cc: Dave Herman; Neil Mix; P T Withington; Brendan Eich; Nicolas
Cannasse;
> es4-discuss at mozilla.org
> Subject: Re: inheriting statics
> 
> Right. So to access a static method of a super-class, where you have
> shadowed it with another method, you must access it via the class
> name..
> 
> I could see this leading to errors, since the override attribute would
> not be used in this context. The same errors could equally happen with
> the existing ES3 scoping rules.
> 
> Is that an argument against inheriting?
> 
> Peter
> 
> On 1/9/07, Jeff Dyer <jodyer at adobe.com> wrote:
> > In AS3 and draft ES4 'super', like 'this', resolves to a value of an
> > instance type, and so in your example below the static foo in A will
not
> > be found by 'super.foo()'.
> >
> > And yes, the definition of foo as a static in class A and an
instance
> > method in class B is allowed. In fact, a static and instance
definition
> > in the same class with the same name is allowed. They appear in
> > different scopes.
> >
> > Jd
> >
> > > -----Original Message-----
> > > From: es4-discuss-admin at mozilla.org
> > [mailto:es4-discuss-admin at mozilla.org]
> > > On Behalf Of Peter Hall
> > > Sent: Tuesday, January 09, 2007 8:16 AM
> > > To: Dave Herman
> > > Cc: Neil Mix; P T Withington; Brendan Eich; Nicolas Cannasse; es4-
> > > discuss at mozilla.org
> > > Subject: Re: inheriting statics
> > >
> > > >
> > > > In other words, statics are inherited and can be redefined,
although
> > > > they are statically resolved, so they have shadowing semantics
(like
> > > > instance fields) rather than overriding.
> > > >
> > >
> > >
> > > So there does not even need to be a requirement that the type of
> > > static variables be related to the type of the variable in the
> > > super-class, or for static method signatures to match.
> > >
> > > But I'm wondering..
> > >
> > > class A {
> > >  public static function foo (){
> > >  }
> > > }
> > >
> > > class B extends A {
> > >    // should this non-static method be allowed?
> > >    public function foo(){
> > >        // and, if so, can I do this?
> > >        super.foo();
> > >    }
> > > }
> > >
> > > class C extends B {
> > >   public static function foo(){
> > >       // and, if so, would this invoke A.foo or be an error?
> > >       super.foo();
> > >   }
> > > }
> > >
> > >
> > > Peter
> > > _______________________________________________
> > > Es4-discuss mailing list
> > > Es4-discuss at mozilla.org
> > > https://mail.mozilla.org/listinfo/es4-discuss
> >




More information about the Es4-discuss mailing list