Liz Keogh query: what about namespace collisions

1 view
Skip to first unread message

Douglas Squirrel

unread,
Dec 3, 2010, 2:21:25 AM12/3/10
to l...@lunivore.com, narrati...@googlegroups.com

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"));

Felix Dilke

unread,
Dec 3, 2010, 4:37:29 AM12/3/10
to narrati...@googlegroups.com, l...@lunivore.com

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

Douglas Squirrel

unread,
Dec 3, 2010, 4:39:40 AM12/3/10
to narrati...@googlegroups.com, l...@lunivore.com

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?

Eric Lefevre-Ardant

unread,
Dec 3, 2010, 4:55:03 AM12/3/10
to narrati...@googlegroups.com, l...@lunivore.com
Well, even if the action methods have the same names, I'd find it very acceptable to have local delegate methods in the test.

private static Action dropSolidObject(String physicalObject) {
    RobotActions.drop(physicalObject);
}

private static Action dropDbTable(String tableName) {
    DatabaseActions.drop(tableName);

Felix Dilke

unread,
Dec 3, 2010, 8:24:07 AM12/3/10
to narrati...@googlegroups.com, l...@lunivore.com

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);

Reply all
Reply to author
Forward
0 new messages