jon ninpoja wrote:how would i manipulate the instance variables or create a new object that is slight different from the previously created button,or one i create after.
is it just done through parameters?
As you can see, there are several ways to do it, but one perfectly valid option which has not really been covered is not to allow internal fields to be changed AT ALL.
Classes like this are called "immutable", and they have many advantages - not the least being that they are naturally Thread-safe. And just because a class is immutable doesn't mean that you can't do some very useful things with it.
java.lang.String is just one example of an immutable class that you can do all sorts of things with, but almost all its "manipulation" methods return a
new String object, rather than changing the one you run the method on.
Obviously, it isn't appropriate for every kind of class - for example, if you have a
Person class, you'll probably want a
changeName() method - but you'll be surprised how many classes can be made immutable. And even for classes that you
can change (these are called "mutable"), you'll probably want to keep the
number of things you can change to a minimum.
So the general rule is: write as many "getter" methods as you like; but think three times before you write a
public "setter" method - and in particular, think
ten times before you write the
first setter method for a class.
HIH
Winston