P
Paul M.
Hi,
Two questions, actually.
1. I have a class Graph which defines this method:
public void addVertex( Vertex someVertex ) {...
The list to which it adds is a private Vector() of Vertex objects.
There is no other public access method to add vertices to a Graph
instance. I can't think of ways that an object of a different type can
end up in the list. I wrote the code-- doesn't mean there aren't any
bugs.
I have another class:
public Vector getVertices() {...
This returns the Vector of Vertex object. When I cycle through the
members of the vector and use them, I cast them as such:
Enumeration enumVertices = graphObject.getVertices().elements();
while( enumVertices.hasNext() ) {
Vertex v = (Vertex) enumVertices.nextElement();
v.doSomethingVeryImportantForManKind();
}
Is there any compelling reason to put the line
Vertex v = (Vertex)...
inside of a try/catch loop and catch a ClassCastException? I can't
think of one, as the the Vector is private and the addVertex method
controls how Objects are added to the Vector. I am using the code in a
GUI and also plan to run
it on very large Graphs, testing for isomorphism, etc. outside of the
GUI.
Question 2 (or is it 3...):
What's a good source, paper or online, to answer questions like this,
especially concerning robustness of code and efficiency. I'm not a
formally-trained programmer-- came up through the ranks of perl (still
love/do it) and I'm used to exception handling along the lines of do {
this(); } or die;
Thanks for your help.
Paul M.
Two questions, actually.
1. I have a class Graph which defines this method:
public void addVertex( Vertex someVertex ) {...
The list to which it adds is a private Vector() of Vertex objects.
There is no other public access method to add vertices to a Graph
instance. I can't think of ways that an object of a different type can
end up in the list. I wrote the code-- doesn't mean there aren't any
bugs.
I have another class:
public Vector getVertices() {...
This returns the Vector of Vertex object. When I cycle through the
members of the vector and use them, I cast them as such:
Enumeration enumVertices = graphObject.getVertices().elements();
while( enumVertices.hasNext() ) {
Vertex v = (Vertex) enumVertices.nextElement();
v.doSomethingVeryImportantForManKind();
}
Is there any compelling reason to put the line
Vertex v = (Vertex)...
inside of a try/catch loop and catch a ClassCastException? I can't
think of one, as the the Vector is private and the addVertex method
controls how Objects are added to the Vector. I am using the code in a
GUI and also plan to run
it on very large Graphs, testing for isomorphism, etc. outside of the
GUI.
Question 2 (or is it 3...):
What's a good source, paper or online, to answer questions like this,
especially concerning robustness of code and efficiency. I'm not a
formally-trained programmer-- came up through the ranks of perl (still
love/do it) and I'm used to exception handling along the lines of do {
this(); } or die;
Thanks for your help.
Paul M.