I would like to present the following dilemma:
Let’s say one needs to use a
Scroll as a main component of a
Page. Everything goes well until the programmer needs to know the current scroll position of the
Scroll (e.g. the viewport of the
Scrollable it contains). The programmer already notices that there is a
scrollTo() position, but there is no
getScrollPosition() or similar.
The programmer then takes a look at the reference implementation of the
Scroll and notices it can obtain the position of the scroll by hooking into
updateViewport(int x, int y, int width, int height). Problem is… that method is
Upon further inspection, it can be noticed that every member of the
Scroll that provides its functionality is actually
private, making extension by subclassing impossible. Thus, a third party programmer is unable to add any additional functionality by simply extending
Scroll, which makes the widget pretty inflexible when more complex behaviors are needed.
The only solution to this problem I can think of is to create a 1:1 copy of the
Scroll class, extending
StyledComposite instead. Of course, creating a complete duplicate of a widget in order to add new functionality is not the best solution because it violates the DRY principle and future updates to the
Scroll class would not reflect into the own implementation.
I would like to both ask for an alternative on how to solve this particular dilemma and suggest a possible improvement of the MicroEJ UI subsystem:
ej.widget.* could use more
protected members, rather than
private members in order to improve extensibility through inheritance. As they are currently implemented, they might as well be declared as
final. This improvement would allow developing widgets which are based upon the vanilla ones, without having to recreate their behavior.
Thank you for your time,