I found some similarities with this recent
Dijkstra example from Cope, in a program of mine that uses the Web API
HTMLElement as extensively as the "Nameable" class in the Dijkstra example.
It has bothered me that in generics and collections we depart from the visible contract of Roles, to a class that needs to be looked up and grasped, before we can understand the Context properly. I can see the issue with an explicit contract everywhere though:
context Dijkstra {
public List<{ string name() }> unvisitedNeighborsOf({ string name() } node) {
List<{ string name() }> allNeighbors = graph_.pathsFrom(node)
List<{ string name() }> retval = new List<{ string name() }>()
for ({ string name() } n : allNeighbors) {
if (unvisiteds_.contains(n)) {
retval.add(n)
}
}
return retval
}
public Dijkstra(NodeGraphInfo graph) {
graph_ = graph
tentativeDistances_ = new Map<{ string name() }, int>()
pathTo = new Map<{ string name() }, { string name() }>()
}
...which doesn't help the readability of the code at all. So should there be some way to create an alias for a contract in a Context, so Nameable can be looked up and understood directly in the Context, or should we say that well-defined classes/interfaces like those in the standardized Web API should be understood as they are? I wouldn't say that an object with simply a name would fall into that case though, so the question still stands.
/Andreas