FlexBASIC class interfaces
There was some discussion over on the FlexProp thread about trying to have the parent object in Spin2 influence child objects, and similar object oriented issues. Solving this for Spin2 is somewhat tricky, and also would need buy-in from the other compiler writers. But FlexBASIC does not have any other implementations (yet) and so we can do some innovation there. So I'd like to use this thread to brainstorm ways we can improve object oriented programming in FlexBASIC.
I'm thinking of use cases like code that wants to interface with @rogloh 's memory drivers, or @jrullan 's GUI library which wants to interface with a low-level drawing object. So for example we want to be able to use the GUI library with different drawing code -- VGA, LCD, HDMI, and so forth. What I'm thinking is that we could define an interface for the low level driver, something like:
interface DrawDriver sub drawPoint(x as integer, y as integer, color as uinteger) sub drawLine(x0 as integer, y0 as integer, x1 as integer, y1 as integer) sub drawBox(x0 as integer, y0 as integer, w as integer, h as integer) sub drawCircle(x0 as integer, y0 as integer, r as integer) end interface
and then our GUI could be declared as something like:
dim drv as DrawDriver function init(d as DrawDriver) as boolean drv = d return true end function sub drawMenu(m as Menu) drv.drawBox(m.topx, m.topy, m.width, m.height) ' and more stuff here end sub
The actual drivers would be declared as regular classes (or Spin2 or C objects) which implement the subroutines and functions specified in the interface. Any class which implements all of these functions could be passed where a DrawDriver is expected. Under the hood the compiler would cast the class to a DrawDriver, which would involve filling out a table of method pointers for you automatically. I think most of this could be done at compile time. There would be a run time overhead, namely functions would have to go through the method pointers rather than jump directly, but I don't think there's any alternative and that is a pretty small overhead.
Thoughts? Alternative suggestions?