• Post Reply Bookmark Topic Watch Topic
  • New Topic

Document interface  RSS feed

 
simon fletcher
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm almost afraid to ask such a "dumb" question but, still being a novice I'll just bite my lip and do it - Here goes...

I'm pretty sure that, up till now, I understand the essential difference between an abstract class (a class, declared as abstract, and that has at least one empty method) and an interface (which isn't a class and has methods that are ALL empty). I've been trying to get my head around using the Document interface and the classes associated with it (DocumnetFilter and FilterBypass, plus DocumentListener interface) but I am finding it tough to properly understand. I just want to make sure that I am 100% right about the fact that the Document interface is the same as all interfaces in that all of it's methods are "empty" and need to be defined in order to do anything. None of it's methods will do anything otherwise, correct?

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes and no :-)

You're right that Document by itself is an interface, and so can't be used to do much of anything. But several non-abstract classes that implement the Document interface exist, so you could use those without having to implement any method yourself. It's only if you wanted to create an entirely new kind of Document that you would have to write all those methods yourself. Or you could subclass AbstractDocument and possibly get away with writing only those methods it declares as abstract.
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simon fletcher wrote:an abstract class (a class, declared as abstract, and that has at least one empty method)

Abstract classes don't need to have any abstract ("empty") methods. They usually do, but the following is perfectly legal:
 
simon fletcher
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just realized this is probably not the right category to have posted this. Sorry.

Thanks, Ulf. That helped put a block in place for me.

Bob, I appreciate your point that you can define a class as abstract , even without it having abstract methods, just so that it has to be extended before it can be instantiated. Are you hinting that this relates to AbstractDocument class somehow? I haven't got my head around it enough yet to know the answer to that, myself.

 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, just correcting a small statement you made. AbstractDocument has one abstract method, getParagraphElement(int pos).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!