gui design about observer pattern

i have 2 swt components both including a browser component.

they both are instatiated passing a reference to an observable document:

publicclass ObservableW3CDocumentextends java.util.Observable{

private Document document;

private String content;

/**

* Modifications to the document should be mirrored in by notifications to

* this document observers

*

* @param document

*/

publicvoid setDocument (Document document){

this.document = document;

if(document.getTextContent()!=null){

this.content = document.getTextContent();

System.out.println("Setting content at: "+content);

}

this.setChanged();

notifyObservers(this);

}

publicvoid setContent (String content){

this.content = content;

try{

this.document = DOMUtil.parseHTML(new StringReader(content));

}catch (SAXException e){

e.printStackTrace();

}catch (IOException e){

e.printStackTrace();

}

this.setChanged();

notifyObservers(this);

}

publicvoid setDocumentAndContent(Document d, String c){

this.document = d;

this.content = c;

this.setChanged();

notifyObservers(this);

}

}

both components implements thejava.util.Observer interface: the first one refresh its content when ever a new document is set (that it, the observable document registers it as an observer).

. the other one should apply an xpath query over it and display the result in its embedded browser.

My question: should I have 2 copies of the same document going around?

How can i make all this updating process easier to mantain?

[2864 byte] By [ervalerioa] at [2007-10-2 4:32:01]
# 1

I have a question mysef:

> Why do you separate Document and content? Would they ever differ? Would it confuse callers if they did differ?

That having been said, within ObservableW3CDocument, you do not have any instances of Document. Instead, you have references to the instance of Document. As such, there is no 'harm' in having multiple references (or in constantly resetting the Document reference). The garbage collector will take care of the actual object when no more valid references exist.

- Saish

Saisha at 2007-7-16 0:02:12 > top of Java-index,Other Topics,Patterns & OO Design...