Liz Keogh (http://lunivore.com/) was kind enough to make some helpful comments on narrative at XP Day this week. I could answer many of her questions but not this one: how do we handle namespace collisions among methods?
For example, suppose I have an Actor who uses two tools, a Robot and a Database. Both tools could sensibly have drop() methods, of course with different meanings: robot.drop("ball") means a ball falls to the ground, while database.drop("users") deletes the users table. Don't we now have an ambiguity when we say the following?
When.the( actor).attempts_to( drop("widgets"));
In this situation, the drop() in
When.the( actor).attempts_to( drop("widgets"));
would generally point to a static (and statically imported) method on some builder class, e.g. RobotActions.drop().
This is independent of the drop() on Robot, although it might well map to it.
So if there are drop() methods on both Robot and Database, they could be used without conflict like this:
define a RobotActions.dropSolidObject() and a DatabaseActions.dropDbTable(), and then have:
import static xx.xx.RobotActions.dropSolidObject;
import static xx.xx.DatabaseActions.dropDbTable;
When.the(actor).attempts_to(dropSolidObject(screwdriver)) // a Robot action
When.the(otherActor).attempts_to(dropDbTable(“user_attributes”)) // a Database action
Hope this helps,
Felix
Thanks Felix - it is obvious I haven't written much narrative code myself! Have we ever encountered a situation where there wasn't a natural disambiguation-by-renaming of the type you describe here?
Not that I know of.
Another fix of course would be to have overloaded methods in the builder, e.g.
drop(SolidObject itemToDrop);
drop(String tableName);