[632] in java-interest
Categories in Java?
daemon@ATHENA.MIT.EDU (Mike Fleming)
Mon Jul 10 14:08:27 1995
From: Mike Fleming <mikef@xnet.com>
To: java-interest@java.sun.com
Date: Mon, 10 Jul 1995 12:48:26 -0500 (CDT)
I was playing around with Java and I came to a point where I needed
to print out an integer in a field of a specific size with leading 0's.
I thought, "no problem, there must be a method in String or Integer for
this". Nope. I thought "No problem, they can't think of everything and
besides, writing a method like this isn't a big deal".
Then I realized "but Java doesn't have categories like Objective-C".
A "category", for those who've never used Objective-C, is a group of methods
that gets added onto a class. It provides a way of splitting up a
complex object into logical sections, a way of adding functionality to
common objects without subclassing, and a way of defining a (in Java)
package-specific set of extensions to more basic objects. Categories
have a name associated with them, as well as a class to which they will be
attached. In Objective-C, categories can be dynamically loaded.
Why not subclass? Suppose that you want your methods to be used everywhere
the old class is used. Besides, it just wouldn't make sense to subclass to
create a method that prints an integer in a specified field...this
functionality represents an extension to an existing class.
I was wondering if categories are being considered as a possible addition
to the language, or if you thought they were a "bad idea." (You decided
to implement protocols/interfaces...)
Mike
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com