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.
Hi members, i'm trying to complete my assignment at present. However, I don't understand how it works of the method toString()in DataInfo class. Also, I woule like to find more information in detail how to work of Observe/observable and how I can use it very well. Thus, I was looking for any good example to understand, but it's not easy. Please let me know if anyone could help in this matter. look forward to hear soon. Paul
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
Thanks a lot for your good explanation regarding the toString() method. I got it now. I also try to add your code and compile to run. I anticipate. Have you got any good example for observer/obxerable? If so, could you show me again when you have a time. Cheers, Paul
author and jackaroo
Hi Paul, Please change your name as requested by the bartender. The link I gave has code which includes Observer Observable pattern in an MVC. However it does not show the Sun Observer interface and Observable classes. From memory the reason it doesnt use Sun's classes is also mentioned in the thread. Are you asking for a simpler example? Something that only shows Observer-Observable so you can see it and understand it without worrying about what else is going on? Or are you asking for something that show's Sun's classes? If so, let us know and we will see what we can do. Regards, Andrew [ May 14, 2003: Message edited by: Andrew Monkhouse ]