>Anyone know how to do something like this C code in Java.
>
>#define Point2fT Tuple2fT
Because I would like a name for my data type that more clearly
represents what it is without having to make a new type.
A point can be a node, a grid, a vertex, an element ... so a node and a
point are the same, yet I would like to use the two names in different
areas for the same thing ... how can I do that?
Monique Y. Mudama - 29 Jul 2005 16:07 GMT
> Because I would like a name for my data type that more clearly
> represents what it is without having to make a new type.
>
> A point can be a node, a grid, a vertex, an element ... so a node
> and a point are the same, yet I would like to use the two names in
> different areas for the same thing ... how can I do that?
I've seen this approach quite often in C++, but to be honest, I don't
think I've ever seen it used in Java.
If you really want to do it, you can extend the point class. But my
gut feel is that rather than making your code more readable, it will
actually obfuscate the code by creating additional, unnecessary
layers.
Why not simply name your variables vertexAB or similar?

Signature
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Carl - 29 Jul 2005 18:27 GMT
> Because I would like a name for my data type that more clearly
> represents what it is without having to make a new type.
>
> A point can be a node, a grid, a vertex, an element ... so a node and a
> point are the same, yet I would like to use the two names in different
> areas for the same thing ... how can I do that?
I also think this is unnecessary and will lead to hard to read code.
Using your examples, a Point does not stop being a point.
A node/element may very well have a point, but if it fails to have any
other distinguishing characteristics, It is very much just a point.
Consider a Class type Node/Element which contains a Point object.
A Grid may have zero or more points. I fail to see the 1-1 relationship
here.
A vertex will indeed _be_ a point, but will be of questionable value
outside of its own context. consider:
Point highPoint = Mountain.getVertex();
The use of a point here is clear, right?
Carl.
Bryce - 29 Jul 2005 19:27 GMT
>Because I would like a name for my data type that more clearly
>represents what it is without having to make a new type.
>
>A point can be a node, a grid, a vertex, an element ... so a node and a
>point are the same, yet I would like to use the two names in different
>areas for the same thing ... how can I do that?
Not really,
A node, grid, vertex, etc are made up of Points... But a Point is a
Point isn't it? If a grid point is different from vertext point, then
just make classes GridPoint and VertexPoint.
YMMV though
--
now with more cowbell