Reputation: 13
I want to share One common variable inside my Swing Application throughout the application life cycle. It should be same Application Context in Servlets .What are the ways i can achieve it?
Upvotes: 0
Views: 113
Reputation: 2383
You could use some kind of singleton, even though I would never recommend singletons in general.
You can also use an IOC container in your Swing application or pass references yourself as needed.
Like @Guillaume said, it doesn't look good in terms of design, but you have options.
You could also use static variables and refactor the code as soon as you understand a bit more the implications of your original design approach, and before the code base grows significantly.
When you start introducing quickly many global objects without rethinking your design, it can introduce issues that you'll not be able to fix for many reasons:
Upvotes: 1