• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marker Interface as antipattern

 
Joseph Miller
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello.

I've seen discussions about the Marker Interface as an antipattern - specifically, as it relates to Cloneable and Serializable. But I've implemented the pattern a number of times (never as a constants interface) and don't really understand the arguments against it. I wonder if any fellow trusty Ranchers can impart some wisdom..?

As an aside, Spring provides the ApplicationContextAware marker and I'm contemplating using it or not...

Thank you for your consideration.
Joe
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Markers are a mis-use of interfaces, but were about all that early developers had. And who hasn't ever turned a bolt with pliers before?
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring's ApplicationContextAware interface is not a marker. It has the method setApplicationContext().
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those are not marker interfaces. Those interfaces give access to underlying language facilities. Therefore, they are not an example of an anti-pattern.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mr. C Lamont Gilbert:
Those are not marker interfaces. Those interfaces give access to underlying language facilities. Therefore, they are not an example of an anti-pattern.


Are you referring to Cloneable and Serializable?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


Are you referring to Cloneable and Serializable?


Yes, as much as I am referring to the cloning and the serializing facilities they provide.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mr. C Lamont Gilbert:


Yes, as much as I am referring to the cloning and the serializing facilities they provide.


Then I don't understand why you think they are not marker interfaces. In my definition, they are: they aren't used for polymorphism, but just to mark a class.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


Then I don't understand why you think they are not marker interfaces. In my definition, they are: they aren't used for polymorphism, but just to mark a class.


Because they don't mark the class for the programming environment. They mark the class for the JVM. instanceof serves no purpose with either of those interfaces. So essentially you can't see the mark.

My position is more strongly against calling them anti-patterns than it is calling them markers though.
[ October 18, 2005: Message edited by: Mr. C Lamont Gilbert ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic