Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Marker Interface  RSS feed

 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,
I have a common question regarding marker interface.Whats the use of a marker Interface,which has no body in it?Which part of Oops concept it is following?
Definite not Inheritance..because It has nothing to inherit.If we google it all website rather giving the proper use all will suggest "Serialize" Interface.But My point is serialize interface doesn't contain any method,so thats the use.I will create a my own user(Marker) interface ,and I will implements to the class which I want to do serialization.But In that case why It didn't work?What happens internally so that it will search for the particular serialize interface only?


I read it all the topics of Interface of javaranch
http://www.coderanch.com/forums/jforum?module=search&action=search&forum=24&match_type=all&sort_by=time&search_keywords=marker+interface
http://www.coderanch.com/how-to/java/Java-FAQ#marker

but still I have doubt.



with regards
Biswomohan Pattanaik
 
Stephan van Hulst
Saloon Keeper
Posts: 7007
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point of marker interfaces is that they signify whether a certain action is allowed on a class, not whether a certain action is possible on a class.

Most of the time, these actions are extralinguistic, or implemented through reflection.

Let's take a look at the Cloneable interface. The action of cloning an object already exists, in the Object class. However, you are not allowed to clone just any object. Classes which permit their instances to be cloned through the clone() method, will implement the Cloneable interface. This interface is empty, and simply signifies that cloning is allowed for that class.
 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:The point of marker interfaces is that they signify whether a certain action is allowed on a class, not whether a certain action is possible on a class.

Most of the time, these actions are extralinguistic, or implemented through reflection.

Let's take a look at the Cloneable interface. The action of cloning an object already exists, in the Object class. However, you are not allowed to clone just any object. Classes which permit their instances to be cloned through the clone() method, will implement the Cloneable interface. This interface is empty, and simply signifies that cloning is allowed for that class.



Thanks Stephan van Hulst
But my point is which part of Oops concept it is following....


with regards
Biswomohan
 
Stephan van Hulst
Saloon Keeper
Posts: 7007
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple interface implementation, I guess. What OOP concept would you call a class implementing an interface that is not a marker interface? It's not inheritance, you can only inherit from classes.

There's no difference in implementing a marker interface an implementing any other interface, other than the number of methods you should implement.

Does it really matter what OOP concept it is, if it is an OOP concept to start with?
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This basically is the concept of reflection ... where you just tell the compiler that your class should be allowed to implement certain functionality
 
Stephan van Hulst
Saloon Keeper
Posts: 7007
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interfaces aren't always used in a reflective manner. Take a look at the RandomAccess interface. Other classes simply base their behaviour on whether or not a list implements this interface.

Also, reflection is not an OOP concept.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:

Also, reflection is not an OOP concept.


I didn't mention that it's an OOP concept ...
 
Stephan van Hulst
Saloon Keeper
Posts: 7007
110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha sorry, it wasn't meant as a criticism. I just meant to clarify to the original poster that not all principles we use are part of OOP.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To van,

hey no need for a sorry buddy ...
i didn't take it as a critic remark.

i think i forgot to add this --> to the previous post
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!