• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tagging Interface  RSS feed

 
megha ghanekar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!!
Can i write my own tagging interface, that i provide in my package. I want users to implement my interfaceis it possible?


Warm Regards,
meghana
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup, quite possible.
Read up on it, any good book should tell you how to do it.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tagging interface is one which consists of a name only, and has no methods. This question seems to come up regularly; I thought there was a thread about it about one week ago, but can't seem to find it. Try the search yourself, see if you can't do better than I did.

There is considerable controversy about whether tagging interfaces ought to be allowed at all, but there are several which are in the API in common use, eg java.io.Serializable and java.rmi.Remote, and it would be impossible to get rid of them. I think there are about three more. Lots of people advise against users writing their own tagging interfaces.

If you are going to write a tagging interface you would have to have a method which requires it. Now that is a very trivial example, showing what you would have to do to use a tagging interface. More to the point, it shows what a useless exercise it would be. All you have achieved is an extra "layer" of complexity in the coding.

You can't implement the methods in a tagging interface because it hasn't got any methods to implement.

CR
[ June 13, 2006: Message edited by: Campbell Ritchie ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is quite right, the question comes up regularly, though more often under the moniker "marker interfaces". The Java Intermediate FAQ has a section on the topic.
[ June 13, 2006: Message edited by: Ulf Dittmer ]
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Ulf Dittmer. No wonder I couldn't find it; I couldn't remember the other name. The thread I was looking for, which has links to the FAQ, is here.
 
megha ghanekar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!!!
how will i force others to implement my interface?
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They have to implement it because that is the nature of the interface. It is by default the essence of the functionality of your program. When you have your "skeleton" signatures up in your interface you will have to use the exact same signature in your method that the interface implements. This method will make it "concrete" and actually do something.

If your question is really to put in some sort of trip code to actually FORCE someone to implement the interface then I don't know of one. It just makes it easier.
 
megha ghanekar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gabriel,
I was talking @ my own tagging interface. And i want to force the users to implement that. I forgot to mention the tagging word.


Warm regards,
meghana
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tagging interface is one which consists of a name only, and has no methods.


Seriously what could the point of this possibly be? I can sort of see what it could be used for but what lesson does it teach?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously what could the point of this possibly be?

Follow the link posted by Campbell; it contains some more in-depth discussion and further links.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a way you could force somebody to implement the interface. You have a method which requires an object of the tagging interface as its parameter. I have already posted a potential example as my first posting on this thread. I have also (as Ulf Dittmer has pointed out) quoted links to other discussion on the same topic, and given an opinion about how useful such an action would be.

Another way is to have a statement in the method throwing an exception if you don't use the interface:-Again, what is the point, except as a training exercise?

CR
 
megha ghanekar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
thanx. I got my answer.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
thanx. I got my answer.
Glad to be able to help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!