The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
SCJP 5
Originally posted by Mohammed EL-Adawi:
Composition can = Aggregation + singelton;
Composition also applies when
1- Clonning
2- constructing the "contained" object inside its containner
Some times Composition is just like private inheritance in c++
class Test {
static A i;
public static void main(String [] args) {
Test.A = new A();
}
}
class A {
}
if I am right,
This is composition, not aggregation, because all Tests object are pointing to the same A object.
SCJP book by K & B, page 164, q2,
answering by B is not correct too.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I'd rather say that private inheritance is one way to implement Composition in C++.
With composition there can be as many instances as you like, but every instance needs to have exactly one owner who responsible for its lifetime cycle.
I would rather say that *no* Test object is referencing an A object - the Test *class* is.
And all objects referencing the same A object would in fact be an indicator that it's *not* composition, because it wouldn't be clear which object is responsible for handling the lifetime of the A object.
SCJP 5
Originally posted by Mohammed EL-Adawi:
1- The A object is owned and referenced by Test class
2- the Test Object(s), can access that static reference, so
practically, Test Object(s) own the ref.
3- but because, it is only one A object, it is not composition.
would you say
Test class aggregate A, but Test object is not?
SCJP book by K & B, page 164, q2,
B- Has-a relationships always rely on instace variables.
is correct statment ? because no such thing like "class aggregation"
regardless of what Sun think.
Phew....Thanks for giving me alot of your time....
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Frank Carver:
Yes, but you need to be very careful with the idea of "ownership" in this sort of context.
Java is a garbage-collecting language, without explicit destruction of objects. The creator of an object can be removed from the system without removing an object it has created, if another object contains a reference to the created object.
True composition at this level is very rare in Java. Almost all objects can be passed around, regardless of where and when they were created.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Frank Carver:
I can see that. Personally I don't often find that this is something particularly valuable to communicate.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Frank Carver:
Personally I don't often find that this is something particularly valuable to communicate.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Consider Paul's rocket mass heater. |