Let's say I need to show Alert
in my code, but before I show it, I would like to add for example my stylesheets and set text that I have already defined in some ResourceBundle.
So if I need this object more in more than one place in code what pattern should I use to do that? And let's say I have more that one such configured Alerts.
I can go with
- wrapper/decorator pattern (but I'll have to extend JavaFX alert and forward all their methods)
- just extend JavaFX alert and make comfortable constructor that will also do my setup
- make factory for this concrete Alert config that will do setup
@Named("ConcreteAlert") Alert concreteAlert
+ Guice (or provider/factory etc.)
But all of these solutions doesn't feel right. Inheritance would provide comfortable instantiation using custom constructor but hard to maintain. As for Guice, there will be too much Named annotations with all my Alerts (but maybe it is fine, IDK).
Sort of Alerts
utility class with static factory named methods for different alerts seems like solution, but I would like to know if it is best fit here.
Aucun commentaire:
Enregistrer un commentaire