#355 Allow scope qualifier on expose

None
open
nobody
5
2012-08-22
2009-05-24
Rick McGuire
No

When writing subclasses, it is sometimes awkward to access variables defined in a superclass. Generally this requires that the superclass add accessor methods which are generally less efficient than direct variable access and may open up access to wider than desired access.

For the expose instruction, it would be nice to qualify the variable on expose the same way method invocations can be used. For example,

expose name:super

would expose the name variable in the super class context. It might be nice to allow an environment symbol to be specified that can allow access to any class in the hierarchy.

If this is done, then the equivalent function should be added to the native APIs to allow native methods equivalent access.

This does expose subclasses a little more to the "fragile base class problem". It might be reasonable to immediately raise an error if a variable exposed in this way does not exist in the super class scope. This would preclude exposing these variables in an init method, but would also introduce a level of reliability since it allows errors to be more easily diagnosed.

Discussion

  • Mark Miesfeld
    Mark Miesfeld
    2009-07-12

    I would find this useful, especially in mixin classes.

    How would the qualifier work in that case? For example, something I had just the other day:

    ::class MyDlg subclas RcDialog inherit AdvancedControls

    where I would have liked to access an object variable in AdvancedControls from the MyDlg subclass.

    Would it be possible to set up that scoping?

     
  • Rick McGuire
    Rick McGuire
    2009-07-12

    That was the intent. Thus you'd be able to specify

    expose foo:.AdvancedControls

    to indicate the scope of the exposed variables.

     


Anonymous


Cancel   Add attachments