File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Interface

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Well i just want to ask that what is the purpose of "marker interface"?
And if it does'nt have body then how it applies default behaviour?
please clear my doubt.
Thanks.
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface usually still has some contract an object must follow, even if there are no methods for enforcing that contract. By implementing the interface you are informing anyone who cares that 'Yes, I know the contract that this Marker represents and this code follows that Contract.'

My favorite example from the API is Serializable. When you look at the API you will see there is a pretty hefty contract that goes along with that interface, all designed to make sure that the instance of any class that implements the Serializable interface can be stored externally to the JVM (to a file, DB, or sent over a socket for examples). There are no methods that the Serializable interface requires, all the work needs to be done from ObjectOutputStreams, and ObjectInputStreams. But my labeling your class as Serializable you tell anyone who reads your code - and the ObjectOuputStream class, that your code can, indeed have its code stored externally following the rules that Serializable sets forth.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47299
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And there's a bit more in one of these FAQ.
 
Bill Shirley
Ranch Hand
Posts: 457
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And note that marker interfaces were a design solution before @annotations were added to the language. You would usually want to implement this behavior with annotations, but there's no pressing reason to change pre-existing marker interfaces into annotations.
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Steve for explaining the marker interface.
Thank you Campbell for giving me examples of marker interface with great deatials.
And Thank you Bill for providing me design level solution.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47299
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic