• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Model View Controller problem

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to implement a MVC problem.
I have a class which extends the TreeMap class. I am trying to make this class Observable so that when any changes occur in the model data, this class informs all the Observer objects.
The problem with the design I am trying to implement is that I cannot extend both TreeMap and Observable at the same time.
I am sure there's an easy solution to this problem that many of you must have come across before.
Please write the soltion:
My existing class looks something like this and I want to make it Observable.
public class MyTreeModel extends TreeMap {

}
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could create an interface as shown below and implement in in your class.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above interface won't work if there are already Observer objects out there expecting a class of java.util.Observable... he'd have to implement his own Observer/Observable classes, which would be a waste of time since Java supplies it's own.

My solution would be to create an inner class that extends Observable and wrap it with your tree model... something like this:



You can then make any other "call-through" methods like addObserver() above that you need. Users of your class call the method on your class and your class calls the method of the wrapped Observable with the parameters passed to it.
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic