views:

19

answers:

1

This question will be asked in a specific form, but applies to a more general question, how to name unordered set items without implying any sort of structure.

In terms of graph theory, a connected, undirected graph will contain vertices that are connected via edges.

When creating an edge class with two member variables that are vertices, representing the two vertices that the edge connects, there was a difficulty in describing the two variables that did not include some form of implied structure.

Consider class Edge{ Vertex v1; Vertex v2; } or class Edge{ Vertex left; Vertex right; } or class Edge{ Vertex a; Vertex b; }

{v1, v2} implies order and a larger possible size than two, though an edge only has two ends.

{a, b} is similar to {v1,v2}, only substiting different symbols.

{left, right} or {up, down} imply direction, which may be counter-intuitive when there is not necessarily any spatial reference to the graph, since raw graphs are pure abstractions.

{start, end} would work for a directed graph but seems arbitrary in an undirected graph.

The closest that I can consider is: class Edge{ Vertex oneEnd; Vertex otherEnd; } but that feels kludgey.

What name complies with good practice for such variables without implying any form of direction, ordering, or structure?

+1  A: 

I'd go with Edge { Vertex v1; Vertex v2; }. I don't think that the user of your code will interpret the numerical suffixes as the order, but simply as differentiators. What if your unordered set contained 10 or 100 items, as could be the case with for example a polygon structure? I'm sure the most intuitive solution would be to use numerical indices/suffixes when naming the items.

Anders Fjeldstad
Surely there is a better name.. someone!