Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2005

Tip: Looking for answers? Try searching our database.

define a new data type

Thread view: 
Wizumwalt@gmail.com - 28 Jul 2005 22:56 GMT
Anyone know how to do something like this C code in Java.

#define Point2fT    Tuple2fT

I have a Tuple2 class which I'd like to define a new data type for as
Point2. So I tried making Tuple2 an interface and extending from that,
but that seemed like overkill.

public class Point2fT extends Tuple2fT ...

Is there a better way to do this?
Bryce - 29 Jul 2005 00:36 GMT
>Anyone know how to do something like this C code in Java.
>
>#define Point2fT    Tuple2fT

Java doesn't have that.

>I have a Tuple2 class which I'd like to define a new data type for as
>Point2. So I tried making Tuple2 an interface and extending from that,
[quoted text clipped - 3 lines]
>
>Is there a better way to do this?

why? I cannot think of any reason to do that, but there may be...
What's your reason?

--
now with more cowbell
Wizumwalt@gmail.com - 29 Jul 2005 15:15 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?
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.