Reputation: 267
So I'm having one super class, Block, that extends Composite and uses the UIBinder to make the layout
class Block extends Composite
I want to create two subclasses for that one, that each have different set of icons that have to be added. For example an InactiveBlock and an ActiveBlock.
My problem here is that I want the layout of both blocks (the icons, and some buttons,labels) to be made through the UIBinder aswell, and then to add that UIBinder (and it's events) to be added to the main Block.
Obviously I can't do something like
class ActiveBlock extends Block, Composite
add(initWidget(UIBinder.create(this)));
How could I accomplish this?
(ps if my question is not clear enough, please do tell so I can elaborate)
Upvotes: 0
Views: 72
Reputation: 797
I would make it a single class with a constructor method having boolean as an input parameter (active/inactive).
So you can define all the common fields and methods in the class, like event handlers, images, etc. And then use the constructor method to add the elements and handlers to the basic widget. Something will be added to all instances, something depending on whether it's active or not.
In this case you won't end up with duplicated code, still will have a benefit of using uibinder, and eventually your code will be simple enough for reading.
Upvotes: 1