This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have 1 class that stores customer info with getters and setters
I would like access the customer class with a GUI class and pump data into it by creating an instance of the customer class (works fine up to here)
Now i have a third GUI class that i would like to retrieve my data from.
The problem is when i make an instance of the customer class in my second GUI class, it resets the data customer class!!
If you create a new instance, then of course it doesn't keep the old settings - those are instance specific.
You should either pass the reference to the object, and use the very same object in both GUI classes, or create a copy of the instance. This means you have to copy all fields as well. The easiest way is to make the class Cloneable, or provide a copy constructor: