• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

toString() and MVC Pattern(observer/observable)

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"pmaeng"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic