Hi Rick, that is what I've been doing on my code (in fact, it's a small variation of what you've suggested). My point and concern is about the API encouraging people to spread Strings throughout the code.
That's it :). Regards 2011/4/3 Rick Bullotta <[email protected]> > Simply create an enum as below, and wherever you use the hardcoded string, > use MyIndexTypes.places.name(). > > public static enum MyIndexTypes { > places, > people, > cars, > nuclearreactors, > vegetables, > headsofstate > } > > -----Original Message----- > From: [email protected] [mailto:[email protected]] > On Behalf Of Adriano Henrique de Almeida > Sent: Saturday, April 02, 2011 10:31 PM > To: [email protected] > Subject: [Neo4j] a small consideration on the index api > > Hi everyone, > > I was playing right now with the index api to do some fulltext search, and > I > found something what I think is not good for the API. > > The index API rely heavily on Strings, just like the following: > > Index<Node> typeIndex = index.forNodes("places"); > > I do write the call to forNodes method all the time I need to use it, like > when creating and when searching with this index and sure, probably I could > do it better, like isolating this on an application scoped component. Thus, > the "places" String got spread all over my code. And then, guess what, I've > made a mistake naming my index. I had to hunt down every "places" String on > my codebase (at this stage it isn't large, but for some other people this > can be). > > My suggestion is to work with something similar at what is done at the > Relationships, with the RelationshipType interface. I never use Strings > when > creating relationships, only enums who implements the interface, and I can > easily refactor it. > > As pointing a problem (at least in my point of view) is good, suggesting a > solution is better :D. Then, my final suggestion would be to create an > interface to the index definitions, like IndexDefinition, and do an > overload > at the forNodes method, that can receive the definition > (forNodex(IndexDefinition)). It will only delegate to the forNodes(String) > method, using the enum, so one can stick with it, if is already using it. > > Of course, I don't know if you guys think that being refactor friendly is > an > major issue for an API, if not, just ignore me ;). > > Best regards. > > -- > Adriano Almeida > Caelum | Ensino e Inovação > www.caelum.com.br > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > -- Adriano Almeida Caelum | Ensino e Inovação www.caelum.com.br _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

