Adam Bien's Weblog

Wednesday Sep 19, 2007

Marker Annotation - for marking concepts, ideas and patterns

During yesterday's smoke test, I checked in the Marker Annotation "Pattern" to p4j5. I borrowed the name from the "Marker Interface" Pattern.
However, I use Marker Annotations to annotate project-wide concepts and ideas in a lean and convenient way. Instead of writing JavaDoc (which is not typesafe - you can mispell the tags), I use lean annotations to mark patterns/idioms/concepts, and JavaDoc for the remaining (parameters, returnvalues etc.) tasks.
Defining an annotation isn't really hard. For e.g. the following snippets is used to mark the "Service" pattern from p4j5:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface Service {
/**
*
* @return The main responsibility of the documented concept.
 */
  String essentialResponsibility();
   /**
    *
    * @return The difference between the concept from MAD and the realization
    */
   String delta() default "";
}

All such annotations has to be defined outside the project and deployed as a jar. Then they can be easily used:

@Service(
 essentialResponsibility="CRUD"
)
public class SeviceBean implemens Service {

}

Some benefits:

  1. Less documentation to write (actually a huge one).
  2. The meta-information is accessible in bytecode and can be processed with e.g. apt.
  3. The architecture can be validated afterwards (e.g. searching for unallowed dependencies between patterns) - the tools are able to access the annotations.
The meaning of the annotation can be kept in the annotation itself and e.g. in wiki. Especially information like:
  • Transactionality
  • Concurrency
  • Remoting (@Local, @Remote)
can be stored in one place. Redundant documentation is nasty to write and maintain...


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Kommentare:

I support that pattern, it actually is one, since I used it myself before reading it here accidentally ;-)

You can use Eclipse TPTP Plugin's Static Code Analysis to discover architectural anti-patterns that way.

That one goes along with a trend to write more and more declarative Java code by use of annotations (see also the Web Beans standard or Guice).

Just my few cents..

Gesendet von Armin Vogt am December 10, 2007 at 12:51 PM CET #

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet
Interviews/About
My Recent Book
Java One 2009
CommunityOne East N.Y.C
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
greenfire.dev.java.net
Links
my.netbeans.org
Visitors
License