Monday, January 28, 2008

Object Extensions

My contribution to the discussion on another blog, concerning possibilities to dynamically extend objects with new methods

If you are allowed to use Java, you can use Groovy (which is bytecode-compatible with Java). Then you can do something like this:

// Define "extension" method within a class
class IntegerCategory {
  static boolean isEven(Integer value) {
  return (value&1) == 0
  }
  }

// Use it
  use (IntegerCategory.class) {
  println 2.isEven()
  println 3.isEven()
  }

I don’t agree that nobody is using Java & comp. for data analyses. There are many users of JAS and jHepWork (certainly not in Atlas). And The Atlas event display - Atlantis - is written in Java.The example I mentioned above was not directly in Java, but in Groovy. Groovy is a kind of Java-extension - dynamically typed language. It is completely compatible with Java (you can freely mix them in one program) and it has many unsafe features which some people would like to have in Java (like operator overloading, multiple inheritance,…). And it has excellent support for XML and SQL. It is, for example, very easy to create a histogram from SQL table: http://hrivnac.free.fr/wordpress/?p=72.

Java itself can support features you have asked for via “Dynamic Proxy”:
http://www.ibm.com/developerworks/java/library/j-jtp08305.html
It is very powerful system, but a bit complex.

[It is strange that all my cotributions are marked as spams - maybe because of included URLs ?]

The complete thread is here.

No comments:

Post a Comment