Can I implement HAS-A relationship by using only instance variables? Or if a class uses a variable of another class, in any scope, it can be stated to be associated with it.
Andy James wrote:Can I implement HAS-A relationship by using only instance variables? Or if a class uses a variable of another class, in any scope, it can be stated to be associated with it.
cheers
Andy
When a class has a reference variable of another class then we can say HAS-A relationship.If you can implement HAS-A relationship through instance variables then please write that code here.
Andy James wrote:
Can you please explain why B3 and B5 aren't 'associated' with A, even though B3 and B5 can manipulate an object of class A?
because only method uses A. it is not a HAS-A relationship.
Thanks for answering my query.
So are we stating -
Class B can share a HAS-A relation with class A only if class B defines an instance or class variable of type A.
Class A is NOT associated with class B, if a method defined in class B uses class A.
I still have doubts about the correctness of the second statement though.
As I stated, I don not agree with - HAS-A relationship cannot be implemented using local variables or method parameters.
I support of my statement (source:http://www.ootips.org/uml-hasa.html):
Problem: UML has several relations (association, aggregation and composition) that seem to all mean the same thing : "has a". So, what is the difference between them?
Robert C. Martin explained:
Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.
Andy James wrote:
Robert C. Martin explained:
Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.
what happen if the particular method is not invoked on an Object?
for example A obj = new A(); is that Object Has-A B?
Andy James wrote:
Robert C. Martin explained:
Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.
what happen if the particular method is not invoked on an Object?
for example A obj = new A(); is that Object Has-A B?
What happens if an instance variable or a class variable is not initialized with an object?
HAS-A relationship is an ability of one instance to send a message to another instance.
cheers
Andy
Post by:autobot
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, that will fit in a stocking