Monday, May 05, 2008

ObjectGraphBuilder - another grooviest builder in Groovy

One of the nicest features of Groovy is Builders. It is a powerful concept and creating your own Domain Specific Languages (DSLs) using this concept is a breeze. Groovy comes with several handy builders like HTML, XML, Swing etc. ObjectGraphBuilder has been a new addition to this family. Just out-of-the-box, this builder comes in very handy and useful for creating complex Object Graphs. Especially, if you have followed javabean conventions, the default strategies implemented in this builder are all good for you and you are ready to go with it. But, what if you have not followed javabean conventions? What if you have followed for some of your objects but not for all? In those situations, you will have the option to override some or all of the default implementations of strategies for which you have violated (rather deviated from) javabean conventions.

Lets taks an example Object Graph that covers most of deviations and see how simple it is to override default implementation strategies to meet those situations.

Lets take the same example from the Groovy doumentation but deviate from javabean conventions for this exercise:

package com.acme class Company { String name Address address List employees = [] } class Address { String line1 String line2 int zip String state } class Employee { String name int employeeId Address address Company company } package com.acme class Company { String name Address address List currentEmployees = [] //deviated from javabean conventions } class Address { String line1 String line2 int zip String state } class Employee { String name int employeeId int id //we have an id property for our own reasons of use Address homeAddress //deviated from javabean conventions String address //not an Address indicating the place but used to specify the form of addressing an Employee (e.g. Mr., Mrs., Ms. etc) Company company }


Since I have deviated from conventions, my ObjectGraphBuilder also needs a deviation from default strategy implementations as well. Makes sese.

Saturday, March 08, 2008

Has Java started becoming legacy? May be "YES".

The history shows that any Programming language staying popular for about 10 years starts attaining the new status of "Legacy" by losing its popularity to new languages. From COBOL to C, C to C++, C++ to Java has proven this. It has been just over 10 years since Java started enjoying its popularity over C++. How long Java can still continue that status is a question.

What is next after Java? It could be the newly becoming popular Dynamic languages.

Java lacks some of the features offered by many recent Dynamic Languages like Ruby, Python, Groovy etc. Is that a problem for Java as a language? I would say "Yes it is in this modern Internet (Web 2.0/Rich Internet Applications(RIA)) and RAD (Rapid Application Development) age. Java as a language lacks dynamisn, suffers expressiveness and human-cenric readability. I believe that is enough for Java to be marked as a legacy language to lose its popularity over the increasingly growing user base of Dynamic/Scripting Languages. Also some of the recent frameworks like Rails and Grails has proven what kind of frameworks can be developed by dynamic languages. Frameworks like these are just impossible with non-dynamic languages.