How determine if an Object Reference is used In Association or Compositon

Hi

Thank you for your time.

I was wondering how can you determine if an object reference is used in association or composition?

Also if possible please explain me the concepts:

I know:

Composition: When a class contains other instances of another class

Aggregation is the same as Composition but it has a different lifetime

Association

- Relationship between instances of two classes.

Wondering if you can provide a better definition.

Thank you,

Alex

[523 byte] By [aterria] at [2007-10-2 3:02:14]
# 1

> Hi

> Thank you for your time.

>

> I was wondering how can you determine if an object

> reference is used in association or composition?

Basically that question doesn't mean anything in terms of java.

Java has objects which a java developer never has direct access to.

Java has references which point to objects and which a java developer does have access to.

A collection has references. One of those references might point to object A.

Another class has another reference. That reference is not and never can be part of the previous collection. It however can also point to A.

--

Given a reference which points to object B there is no way in standard java to determine if that object has another reference somewhere else.

It might be possible to do this using the debugger api (determining that is up to you.) Even if it does that isn't something that a 'normal' application should be doing.

jschella at 2007-7-15 21:28:35 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Thank you for answering my question.All my questions have been answered.
aterria at 2007-7-15 21:28:35 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Just for anyone's benefit reading this....

An association is simply a reference from one object to another (A "uses" B, for example).

Composition refers to the fact that one object is made up of another object or objects. In this instance, A "has" B, and is often defined by B.

For example, a car might be associated with a driver (or vice versa), but a car is composed of parts. The parts define the car (composition), the driver merely uses it (association).

nanjoutaia at 2007-7-15 21:28:35 > top of Java-index,Other Topics,Patterns & OO Design...