• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Marker Interface as antipattern

 
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
 
(instanceof Sidekick)
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?
 
Marshal
Posts: 15876
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring's ApplicationContextAware interface is not a marker. It has the method setApplicationContext().
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE 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.
 
author
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
Hibernate Eclipse IDE 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
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
Hibernate Eclipse IDE 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 ]
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic