aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Marker Interface as antipattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Marker Interface as antipattern" Watch "Marker Interface as antipattern" New topic
Author

Marker Interface as antipattern

Joseph Miller
Greenhorn

Joined: Jun 19, 2001
Posts: 21
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

Joined: Jan 29, 2003
Posts: 8791
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?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Spring's ApplicationContextAware interface is not a marker. It has the method setApplicationContext().


Junilu - [How to Ask Questions] [How to Answer Questions]
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

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

Joined: Jul 11, 2001
Posts: 14112
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?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Oct 05, 2001
Posts: 1170

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marker Interface as antipattern
 
Similar Threads
Java
marker interface
Marker Interface purpose
Marker Interface
What is advantage of marker interface?