Re: Unable to Reuse Object (JAVA)
The singleton sounds pretty much exactly what you want, it basically give global access to an object (in your case, your User object). Any other class in your application can access this user object and use its methods etc.
What you could do, is initialise the singleton when the user logs in. Then any other part of your application could use the information for that user.
Let's say your singleton is called User, the bits in your application code could be like:
String name = User.getInstance().getFullName();
The singleton pattern is sometimes criticised or introducing "global state" in an application... but you would be surprised how much this is used in the real world.
Last edited by KdotJ; December 2nd, 2012 at 10:27 PM.
- "Make me a coffee..."
- "sudo make me a coffee"