• Post Reply Bookmark Topic Watch Topic
  • New Topic

Markable Interface!!!  RSS feed

 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anybody explain about markable Interface(excat need,etc.)?

Thanx in Advance

Sachin Dimble.

- India_Will_Become_SuperITPower(new Lets_Go_ForIt());
 
Manoj Kumkumath
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker Interface is actually falls under fundamental java design patterns. It helps to determine something about objects without assuming they are an instance of any particular class.

So If your instance is of type Serializable, it helps to identify that this instance is serializable.

Since it is used to mark a instance, there won't be any methods or variables.
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx A ton Manoj!!!

Sachin Dimble.


- India_Will_Become_SuperITPower(new Lets_Go_ForIt());
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker Interface is actually falls under fundamental java design patterns.


Where did you get that idea? It is absolutely not fundamental, and as far as patterns go, I would call it an anti-pattern which is to be avoided. Nowadays one would use annotations to accomplish the purpose they serve in earlier JDK versions.

And just because it always gets asked, here's a list of marker interfaces: java.io.Serializable, java.lang.Clonable, java.rmi.Remote, java.util.EventListener, javax.servlet.SingleThreadModel
 
Manoj Kumkumath
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patterns in Java Vol 1 by Mark Grand.

Could you share why you think this falls under Antipatterns?

Any reference will be helpful.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interfaces are a hack to add metadata to source code - that's why Ulf calls it an anti-pattern. The annotations introduced in Java 1.5 are especially made for including metadata.

Note that there are other ad-hoc solutions to add metadata in Java source code, such as the 'transient' keyword.

Look at the annotations tutorial to learn more about annotations.
 
Manoj Kumkumath
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
That makes sense.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interfaces are a mis-use of a language feature, which have been used for varying, unrelated purposes. Note that the ones mentioned earlier are age-old, and that Sun has not added any new ones recently (although I'm sure the list is not complete).

If an operation is not supported by an object, it can throw an exception if the operation is attempted, like Collection.remove does, but having a public clone method and not being allowed to call it is strange. In the case of EventListener it's not even clear what it does, while SingleThreadModel specifies an deployment/runtime detail.

Ken Arnold, who was/is behind several Java APIs at Sun, sounds off on marker interfaces here, noting that they should rarely be used.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
Marker interfaces are a mis-use of a language feature, which have been used for varying, unrelated purposes. Note that the ones mentioned earlier are age-old, and that Sun has not added any new ones recently (although I'm sure the list is not complete).

If an operation is not supported by an object, it can throw an exception if the operation is attempted, like Collection.remove does, but having a public clone method and not being allowed to call it is strange. In the case of EventListener it's not even clear what it does, while SingleThreadModel specifies an deployment/runtime detail.

Ken Arnold, who was/is behind several Java APIs at Sun, sounds off on marker interfaces here, noting that they should rarely be used.


One possible indication of this is that you will perhaps never do the following:



Talking about interfaces, both making them marker interfaces and declaring constants in them are antipatternish.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!