Aaron Harnly wrote:
> One question: What exactly is the purpose of the Edge classes at this
> point?
>
> There's all this bother in specifying the type for generics, and passing
> the class, yet they seem to do very little. As far as I can tell,
> there's no particular interface they need implement, nor any public
> methods in the DefaultEdge class. So is it being held onto just in case
> we want to subclass and add our own behaviors? Yet it the edge doesn't
> know its source and target vertices, how much interesting behavior could
> we really add -- or is the idea mainly leaving room for arbitrary
> labels, for example?
It's type-safety in general (labels are just one possible use). To take
today's current fad, suppose you're modeling a social network; you might
have class Person as vertex and class Relationship as edge, where
Relationship has extra attributes like isFriend, isColleague, or isEnemy
(I'm still waiting for anti-social networking).
Then you would do things like
Graph<Person,Relationship> socialNetwork = ...;
Relationship r = socialNetwork.getEdge(valjean, javert);
if (r.isFriend()) {
...
}
No more casting. However, you may only have a vertex class but no edge
class; in that case you have to specify DefaultEdge everywhere, which is
a pain. Maybe one day Sun will add default values for generic
parameters (available in C++ templates for years now).
Note that when using an edge class, it increases efficiency if you make
it extend DefaultEdge, because intrusive references hidden in
IntrusiveEdge allow us to avoid hash-lookups in the implementations of
getEdgeSource and getEdgeTarget.
JVS
|