|
Re: What's On Your Java SE 7 Wish List?
|
Posted: Jan 1, 2007 12:26 PM
|
|
Hi,
There are two features which I would like to have integrated in Java. One is real-closures and the second is a concept known in Objective-C as Categories.
Regarding real-closures I agree all arguments given in favour of that feature.
In order to explain best the "categories" concept I will quote wikipedia.
START Quotation:
Categories
Cox's main concern was the maintainability of large code bases. Experience from the structured programming world had shown that one of the main ways to improve code was to break it down into smaller pieces. Objective-C added the concept of Categories to help with this process.
A category collects method implementations into separate files. The programmer can place groups of related methods into a category to make them more readable. For instance, one could create a "SpellChecking" category "on" the String object, collecting all of the methods related to spell checking into a single place.
Furthermore, the methods within a category are added to a class at runtime. Thus, categories permit the programmer to add methods to an existing class without the need to recompile that class or even have access to its source code. For example, if the system you are supplied with does not contain a spell checker in its String implementation, you can add it without modifying the String source code.
Methods within categories become indistinguishable from the methods in a class when the program is run. A category has full access to all of the instance variables within the class, including private variables.
Categories provide an elegant solution to the fragile base class problem for methods.
If you declare a method in a category with the same method signature as an existing method in a class, the category's method is adopted. Thus categories can not only add methods to a class, but also replace existing methods. This feature can be used to fix bugs in other classes by rewriting their methods, or to cause a global change to a class's behavior within a program. If two categories have methods with the same method signature, it is undefined which category's method is adopted.
Other languages have attempted to add this feature in a variety of ways. TOM took the Objective-C system a step further and allowed for the addition of variables as well. Other languages have instead used prototype oriented solutions, the most notable being Self.
END Quotation
Well, we all know that some part of the JRE is well designed and other not. This concept would help to improve the framework. Furthermore we implement a lot of utility classes in order to provide that funtionality which is not supported by classes of the JRE. Categories is an elegant way to extend given Types without changing their identiy. E.g the String class would remain teh String class but with improved functionality.
I have work as an software developer using objective-c for a long time and can confirm that this feature comes with great flexibility and elegance.
bye Juan Carlos Flores Beltran
|
|