Himanshu was speaking of static imports in Jdk 5. Not surprisingly, I had something to learn over here too. Jdk 5 has come up with a feature for importing static variables; the fact that the same is applicable to methods and object references was news for me. I never thought of it before. What are the implications? Well like every feature and tool this adds a new destructive angle to the object oriented paradigm. It is better not to teach static imports to beginners. (Hey this is my blog.. don’t' contest).
With access specifiers of type 'public final static' there is no problem at all. Essentially making imported entities read only. But if we have a static object reference or method, the object oriented ness is lost. The static methods themselves are stateless. The seemingly non-object oriented way of accessing methods and references is what concerns me. The static methods themselves are stateless. We have discussed their usage in a earlier blog. The static references and methods are more of a concern to me.
These are most often seen in large scale programming applications. To start of 'Singleton' pattern is one of the most popular patterns built around static reference concept. 'Factory' pattern is another example of using static methods. The fact that
, some crazy guy wants to increase performance sends jitters.(by changing the access specifier to public, use static imports and invoke the functionality, and thus save a 'precious' method call). Do we break the paradigm for the sake of small performance gains?
All said, this adds more emphasis on code reviews and another aspect to the taken care of when carrying out code reviews.
No comments:
Post a Comment