Abstraction ideas, cont’d

Fortress imposes a restriction on abstraction that’s a sizable departure from the OO type system in Java: Objects, the only “classes” with actual data, cannot be extended. That is, in Fortress, every class that contains an actual structural representation is like a final class in Java.

Here’s where this could go wrong: Say I wrote some library code that involved the following object:

object ButtonWidget(x: ZZ, y: ZZ, w: ZZ, h: ZZ) extends Widget
  clickHandler:Maybe[\Click->()\]
  render():() = ...
end
addButton(b: ButtonWidget):() = ...

Then as a user of this library I want to extend the button to have a color:

object MyButton(x: ZZ, y: ZZ, w: ZZ, h: ZZ, c: Color) extends ButtonWidget
  ...
end
addButton(MyButton(0, 0, 20, 10, blue))

Uh oh, I can’t extend an object. How do I get that ad-hoc polymorphism from class extension in Java? I could probably use the API/component system (which I have largely ignored in all my thinking) to setup widgets in some API. I could have also defined ButtonWidget as a trait with abstract field declarations, but it seems limiting to always avoid objects in library code.