Aug 31, 2011, 4:18 AM
66 Posts

Is it safe to extend Document class?

  • Category: Other
  • Platform: All
  • Release: 8.5.3
  • Role:
  • Tags:
  • Replies: 5
Is it safe to extend Document class and use it instead of std. Document? Idea behind is to add some methods that we usually use when working with document and which are now part of of our JAVA library. If this is possible this would make a quite smooth integration of new functions into existing Domino classes. 
 
 
e.g.
import lotus.notes.Database;
import lotus.notes.Document;
import lotus.notes.NotesException;
import lotus.notes.Session;

public class MyNotesDocument extends Document {

public MyNotesDocument() throws NotesException {
// TODO Auto-generated constructor stub
}

public MyNotesDocument(Session arg0, long arg1) throws NotesException {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}

public MyNotesDocument(Database arg0, long arg1) throws NotesException {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}

}
 
Aug 31, 2011, 12:43 PM
64 Posts
Re: Is it safe to extend Document class?
- I don't see why it wouldn't be "safe", since extension is a fundamental aspect of Java, and I presume it's not marked "final" so it may be extended.  Even if Document changes later, the derived class should still work as well as Document itself would.  For an extreme example, if Lotus changed Document.save() to Document.commit(), your derived class would fail.  But so would anything that uses Document directly, so nothing is "lost" by derivation.
 
Hope this helps...
Aug 31, 2011, 1:49 PM
272 Posts
Re: Is it safe to extend Document class?
An interesting question is what would happen to the class if the document is destroyed because of recycling. What happens to the extended class?
 
Sven
Aug 31, 2011, 2:13 PM
66 Posts
Re: Is it safe to extend Document class?
 Well I just created a quick NotesDocument derived from Document but it raises errors when working with it ... in different places of Domino API.
Aug 31, 2011, 2:34 PM
39 Posts
Re: Is it safe to extend Document class?
You might try creating a wrapper class around it, and have a Constructor that takes a Document and a getDocument() method so you can get the Document out.  IBM already has a wrapped class for xpages in
com.ibm.xsp.model.domino.wrapped.DominoDocument

 Thanks
-Toby
Sep 1, 2011, 6:36 PM
64 Posts
Looks like it may be final...
- Since IBM is wrapping that itself.  I think Toby's got the ticket...