• Post Reply Bookmark Topic Watch Topic
  • New Topic

Model View Controller problem

 
Rohan Baweja
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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 {

}
 
Tim Troy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create an interface as shown below and implement in in your class.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!