Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disadvantages of marker interface

 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the disadvantages of marker interface, if any?
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at here
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Pramod

The link you shared is very obscure Could you please conclude it in more undersatndable language about What are the disadvantages of marker interfaces?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this FAQ any better?
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Is this FAQ any better?


That link, shared by you, only tells that Annotation is better than using Marker interfaces..but it doesn't tell us what are the disadvantages of using marker interface?

Could you please give me some relevant information regarding my question?
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no disadvantages to marker interfaces, except that they clutter your code.

The point is that you shouldn't use them, because they have no advantages whatsoever.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do you also disagree with the use of marker interfaces in validation, such as JSR-303 where marker interfaces are used within annotations to specify which validation should be carried out?

Sean
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it necessary this is done using interfaces?
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Why is it necessary this is done using interfaces?

It is not unless you wish to use groups, which is where the link pointed to.
Sean
 
Sreelatha Sankaranarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annotations and marker interfaces are pretty much used for the same purpose, however annotations can be used on class,method or variable whereas marker interfaces can be used only on classes , maybe the only disadvantage of marker interfaces over annotations.
 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean, my point is, couldn't they have implemented it without forcing you to use interfaces?

The link you pointed me to is a bit much for me to go over it right now, and I'm not familiar with the validation described therein.

You can engineer any situation to require marker interfaces, and it gives them a purpose, but not an advantage. I think the use of marker interfaces is pure abuse of the language.
The sheer fact that they are named separately because they are being used for a different purpose than they were originally intended, doesn't speak in favour of them.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of these days I'll change the forum software to force anyone who wants to use "marker interface" in the subject line of a new post to read at least 10 previous topics on the subject (which are easily found through the site search).

 
Stephan van Hulst
Bartender
Pie
Posts: 5589
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha,
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interfaces, such as Serializable, have the same function as annotations - they are used to specify certain properties (metadata) of classes, methods, fields etc.

I can understand Stephan when he says that this is abuse of the language - the main purpose of interfaces is to specify a set of methods that a class must implement. Somebody came up with a different usage - for providing metadata, and so the idea of marker interfaces was born.

The main purpose of annotations is exactly to provide metadata, so you should prefer to use annotations for that, and not marker interfaces.

Annotations are also more flexible than marker interfaces. Annotations can have parameters and can not only be applied to classes, but to methods, fields etc. as well. So, there you have a disadvantage of marker interfaces, when compared to annotations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic