My question will be about how do you think it would be fit to name some methods in a fluent interface. Let me try to demonstrate the problem.
Consider this relation tree:
A person can have dogs and cats, and a dog can have bones. Pretty simple.
What i'm trying to do is create a domain specific fluent interface for determining, which ones of these relations does the user need. It is able to handle any depth of relationships.
I designed the operation something like this (It is building the assoicaiton tree, from which i can determine, what the user wants):
As code (it may be more readable):
personAssoc = person.associate().withCats().and().withDogs().withBones().up().done();
But i'm trying to make this part as intuitive as possible, so i wan't the method names to make sense after each other, and be as close to spoken language as possible. My biggest concerns are the following 3 method names:
and()in my language of choice
andis a reserved keyword, so i can't use it. I looked up synonyms (
also()) but they don't sound/look right (
andmeans, that we will add more children to the parent association).
up()it is obviously breaking any kind of flow. With this method name, the whole thing became a lot further away from spoken language, than i wanted to (
upmeans, we are not necessary wan't to add more relations to the parent, but we are done with the current one. In code it is the same as
done()is only called once, at the end of the method calls, but still doesn't fit the picture (
donemeans, that we are literally done, we won't add more associations).
What i'm looking for is other, better names for the above 3, which:
- Which make the usage of the fluent interface closer to spoken language.
anda name, which is as far as possible from any language keywords.
If you read this whole thing, feel free to drop by any ideas, it might help me out a great deal! Thank you for any suggestion.