Re: Purpose of an empty Interface ??
- From: "Doug" <DugzDC@xxxxxxxxxxxxxxxx>
- Date: 10 Aug 2006 16:59:42 -0700
Aki Tuomi wrote:
Doug kirjoitti:
addverma@xxxxxxxxxxxx wrote:Except that those are not empty interfaces.
While going through the javax package of JMS I came across an empty
Interface, "javax.jms.ConnectionFactory". This interface was empty. No
fields and no methods. Two interfaces, implemented this empty
interface, "javax.jms.QueueConnectionFactory" and
"javax.jms.TopicConnectionFactory."
This got me thinking, what can be the purpose of having an empty
interface? Coding cannot be done with such an interface. No methods can
be invoked on such an interface. There are no constant fields also,
which can be used. So what purpose does an empty interface serve?
Shouldn't such type of constructs be disallowed ?
This question does not apply to JAVA but to general OOP. I did see this
in JAVA, but can be applied to most of the OOP languages. There can be
"empty" abstract classes and interfaces in other languages.
There are two different schools of thought on whether empty interfaces
are good or not. I won't post my opinion, but...
One 'use' of empty interfaces is as marker classes. By marking a class
as implementing an empty interface, you indicate that some kind of
operation is allowed on it or it supports some kind of behaviour.
This can obviously be used by user code (depending on which of those
two schools you go to), but I can think of two specific examples that
the JVM/compiler itself uses:
- Cloneable indicates that Object.clone() will work on a class that
implements it (with a byte-for-byte copy)
- Serializable indicates the object can be serliased
ymmv,
Doug
Aki
Hi Aki,
I'm not a Java expert, so I'm probably wrong! The docs seem to
indicate they're empty though:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Cloneable.html
and
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
Although I grant you that the latter has 'special' funcs you can
implement if you have specific needs.
Are these not considered empty interfaces?
Thanks,
Doug
.
- References:
- Purpose of an empty Interface ??
- From: addverma
- Re: Purpose of an empty Interface ??
- From: Doug
- Re: Purpose of an empty Interface ??
- From: Aki Tuomi
- Purpose of an empty Interface ??
- Prev by Date: Re: Sugar coating the bitter pill.
- Next by Date: Re: TDD doesn't suck
- Previous by thread: Re: Purpose of an empty Interface ??
- Next by thread: Re: TDD doesn't suck
- Index(es):
Relevant Pages
|