Skip to main content

Method categories

12 replies [Last post]
satai
Offline
Joined: 2004-04-27
Points: 0

In the Smalltalk language there is a nice feature - Classes and methods can have set a category. In Java classes are divided into packages, but there is lack of method categories.

Category has only a documenting meaning, it has no importance for building and running the application. You just say, that the method is, for example, initializing instances. And an other method can be marked as "converting" and anybody now knows, that the method is used to convert the object to any other type or via versa. Probably the most usual and useful usage of such as marking is generating javadoc - you can generate javadoc that would have methods divided into categories. Such a documentation would be generally more useful.

It would be useful, to have a set of common categories, that are well known by all developers. Developers can, of course, use their project specific categories (for example "CustomerSupport").

Probably the most natural way to add categories is to add a @category("name") anotation for method or add @category as a javadoc tag.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kcpeppe
Offline
Joined: 2003-06-15
Points: 0

method categories are a convenience feature of the IDE. This is not Java doc, it's a way of organizing or viewing groups of related methods.

mikeazzi
Offline
Joined: 2003-08-11
Points: 0

Well I, for one, see another interesting use for that besides documentation. I think it can be used in aspect oriented programming, particularly as a way of defining point cuts, where you can say for example, apply this aspect to all methods of a certain category.
I think we can also expand on this method category idea by utilizing RDF models/concepts to categorize methods. I even envision some sort of ontologies (libraries of categories) for method categories.

Mike

satai
Offline
Joined: 2004-04-27
Points: 0

Usage of javadoc would be fain. But usage of anotations would bring some more benefits - remember Smalltalk browser, in that you can in runtime browse categorised methods...

behrangsa
Offline
Joined: 2003-09-14
Points: 0

I vote for method categories too.

Message was edited by: behrangsa

ninkibah
Offline
Joined: 2003-12-12
Points: 0

If you are an Eclipse user, you can try the Protocols plugin.

The only change to your source code is that it adds a comment line with the name of the protocol. Any methods coming after that comment line are shown as members of that category.

Neat and simple solution, no need to change the language, just your tools!

satai
Offline
Joined: 2004-04-27
Points: 0

Nice solution, but not too systematic and solves just a subset of categories possibilities.

monika_krug
Offline
Joined: 2004-10-14
Points: 0

I don't see a use for that. If it's only documentary, why not just use Javadoc for this purpose?

Monika.

patrikbeno
Offline
Joined: 2004-10-11
Points: 0

Well, yes and no, I think. We have two choices:

1) use javadoc for this, utilize javadoc tags. Still, javadoc must support this to be able to group methods by category in docs

2) if we use annotations for this, we can easily switch from docs-only mode to runtime mode. imagine JMX bean that exposes its management capabilities groupped by category. You will be able to use the same mechanism for both documentation (javadoc) and runtime (e.g. JMX GUI)

angben
Offline
Joined: 2004-10-07
Points: 0

Yes, I think that annotations are the best way to implement this requested feature.

patrikbeno
Offline
Joined: 2004-10-11
Points: 0

+1
seems like a good idea. I really missed this sometimes

denismo
Offline
Joined: 2003-06-28
Points: 0

Yes, this is a good idea. There are many known categories - factories, constructors, "descructors", converters, string representation, comparision, property accessors, enumerators, container/child relationship, and so on.

Some of this has actually been proposed officially: http://java.sun.com/j2se/javadoc/proposed-tags.html

Votes are welcome.

satai
Offline
Joined: 2004-04-27
Points: 0

Standard smalltalk ones are:
accessing (geter and seters), instance (factory), initialize, copying, printing, fileIn/Out, testing (isSomething etc), converting (asSomething etc.), private (doesn't make any sense in java), examples

I would enjoy some other such as unitTesting.