Hi Paul,
Try adding this code into the DataInfo class:
Compile it and run it.
You should see something like:
suncertify.db.DataInfo@16f0472recordNumber = 3
Fields:Name = Title value = Mr
Name = LastName value = Jones
Now comment out the entire
toString() method, comile it and run it again. This time you should see something like:
suncertify.db.DataInfo@1ea2dfe
Basically, the
toString() method is called whenever you use an instance of a class in a place where a
String is expected ... in the case of the code I provided above, I was using the instance of the class in the
System.out.println() which expects Strings as parameters.
As you saw, without a custom
toString method, the output was just the hashCode - not very usefull if you are printing this out in order to debug your code.
But when you override the to
toString method, you can have a much more meaningful output.
You can override the
toString method in all your classes so that a user can get a meaningful view of what is happening in your class at any given time.
As for the MVC, try looking at:
The
Sun Model View Controller blueprint for an explanation of what the responsibilities of each item is.
Also, try looking at
this thread which has a very good explanation and some sample code.
Regards, Andrew