Association Class

Z

ZyLo

Hello. I guess I'm not a relative newcomer to Java, but it has been
too long that I did any actual programming and not just design work
that I'm stumping myself on what I think should be a relatively simple
problem.

I have a class that has a list of objects in it. I want to make an
association class separate from this class that uses specific objects
in that classes' lists to define an association. For instance:

I am considering a scheduling problem. I have lists of various object
types: people, timeslots, room assignments, classes etc. I have a plan
to make an association class, conflicts.java, that would contain an
association of pointers to the items in these lists that are
conflicting.

If a person is scheduled back-to-back for the same class, that would be
a conflict with the person and the room and timeslots, all of which are
objects in separate lists. Also, a conflict might be that the person's
maximum hour load is reached, and the relationship is that this person
is in conflict with it's own boundaries of hours. I don't want to
simply deny that the users who use this program not be allowed to
create conflicts, but rather, use this association class to 'mark' the
conflicts that are created, until they are later fixed by the user at
his/her discretion.

How can I do this? I was thinking that simply creating pointers to the
other classes' lists would be fine, but 1) I'm not experienced with
Java and dont' remember/know how to do that and 2) I am not certain on
what "every object in Java is a pointer" really means, especially in
this context. Can someone help me out on this?

Thank you.
 
K

kaeli

How can I do this? I was thinking that simply creating pointers to the
other classes' lists would be fine,

That's debatable. ;)
but 1) I'm not experienced with
Java and dont' remember/know how to do that

There are no pointers in Java.
Every object in Java is a pointer.

Matrix said:
and 2) I am not certain on
what "every object in Java is a pointer" really means, especially in
this context. Can someone help me out on this?

Java, unlike C, does not let you dereference pointers.
But every object is really just a reference to a memory location (therefore,
for all intents and purposes, a pointer). You just usually have a hard time
finding out what that location is, and you can't do funky things with it like
you can in C.

Just store your objects in a hashtable, hashmap, arraylist, vector, or
however you find most appropriate for what you're doing.
For example, say your classes' lists are all of type ArrayList, you can store
those as one big hash or vector or even another arraylist in your other
class.

I'm not saying that's the best design, because I don't think it is. But you
CAN.

--
 
C

Chris Smith

kaeli said:
There are no pointers in Java.
Every object in Java is a pointer.

Matrix, anyone? <heh>

Yes, but I'd use very different terminology in order to coincide with
mainstream usage. In Java, an "object" is *not* a kind of variable.
Variables are either:

1) Primitives (int, long, etc.)
2) References

A reference, in turn, is either:

1) A pointer to an object
2) The value 'null'

The important thing to realize is this: an object does not have any kind
of name or identifier, so it can never be expressed directly in Java.
You can only do things to references, which point to objects.

You are using "object" to mean a reference, and that could get
confusing, since practically all other sources use words the other way
around (not to mention that references have little in common with
objects from OO theory).
Java, unlike C, does not let you dereference pointers.

Sure it does. There are several operators that dereference pointers;
notably "." (accessing object members) and "[]" (array indexing).
Anything that can generate a NullPointerException at a language level is
a dereferencing of a pointer.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
K

kaeli

Java, unlike C, does not let you dereference pointers.

Sure it does. There are several operators that dereference pointers;
notably "." (accessing object members) and "[]" (array indexing).
Anything that can generate a NullPointerException at a language level is
a dereferencing of a pointer.

I meant I can't get a memory address and [add, subtract, mult, div] a value
to it to get another memory address and then put that into a variable and use
it.
And I literally mean the memory address -- not something that stands for it.
Pointer arithmetic. Maybe I should have used another term for it.

Put it this way: I can't play with memory addresses in Java like I can in C.
;)
I suck at terminology, I guess.

--
--
~kaeli~
Kill one man and you are a murderer. Kill millions and you
are a conqueror. Kill everyone and you are God.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
C

Chris Smith

kaeli said:
I meant I can't get a memory address and [add, subtract, mult, div] a value
to it to get another memory address and then put that into a variable and use
it. And I literally mean the memory address -- not something that stands
for it.

Ah yes, you mean that you can't convert a pointer to an integer. That
much is true. I was confused by your use of the term "dereference",
which has a specific technical meaning (specifically, following a
pointer to read or write to storage that depends on the value of the
pointer).

Sorry about that,

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
K

kaeli

kaeli said:
I meant I can't get a memory address and [add, subtract, mult, div] a value
to it to get another memory address and then put that into a variable and use
it. And I literally mean the memory address -- not something that stands
for it.

Ah yes, you mean that you can't convert a pointer to an integer. That
much is true. I was confused by your use of the term "dereference",
which has a specific technical meaning (specifically, following a
pointer to read or write to storage that depends on the value of the
pointer).

Sorry about that,

Oh, no, my bad. I used the wrong word. Wasn't the first time, won't be the
last. ;)


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top