I agree that you're taking things too literally :P However, it can be argued that this is a poor implementation of a die, unless you're taking about a low level object (like a random number generator).
A die isn't an object that actually does something. It's a class that "knows" something. People are going to ask it what it knows and then make a decision based on that information. Instead the die should be making the decision.
For example, a die might be used in a board game to decide which path to take. It's the die that should be choosing the path. A procedural implementation might be:
int value = die.roll();
switch (value)
{
// Logic to pick the path. The result is a variable named path.
}
player1.follow(path);
A high level object oriented implementation would be to place the decision logic in the die and the location logic in the path. You let the object that knows things make the decisions that results that logic. This is called the Tell Don't Ask principle. A Tell Don't Ask implementation would look like this:
die .chooseFrom(paths) .lead(player1);
Rather than:
- Asking the die for a value, using that value to choose a path, and having the player follow that path,
- The die chooses a path which leads the player.
The game can be written as a loop that makes this call until something happens.
This makes a little less sense if you take it literally. A die can't roll itself, much less pick a path, but you have to think outside the box. It's not exactly easy to think this way. A more programming specific version of this pattern is the internal iterator.
You may be used to doing this:
for (IIterator it = col.iterator(); it.hasNext(); )
{
accumulate(it.next());
}
out.append(accumulate.result());
However, it's arguable that .hasNext() and .next() should be a single state since they can't be inconsistent from each other. An internal iterator lets you do this:
col.apply(accumulate).appendTo(out);