Have a Form Inherit the Layout Class

They considered that approach, but it creates its own problems.

For example, suppose that both the Layout and the descendant Form each define member function show, to respond to the corresponding event. With inheritance, there is now a conflict:

  • Which one will the event-handling system find: the Layout’s show, or the descendant’s show?
  • Does it depend on some screwy accident of timing? E.g., when the handler is registered?
  • Which one should be called? Depending on the situation, there are good arguments both ways.
  • Or should both be called? In what order?

Conflicts and complications like these tend to make the situation harder to teach, understand, code for, and debug. They are inevitable with inheritance – but not with containment.

With containment, the layout is a separate object, and can have its own event-handlers, for transparent self-management, with no interference from the Form that uses the Layout.

That said, I’m sure that our Anvil friends will find ways to make the integration easier, wherever there are concerns that span both objects.

1 Like