Hi
I would like to know which of the following is correct uni-directional association between class A and class B.(A->B)
1.
class A
{
int num;
B obj_B;
A(){
//constructor code;
}
}
class B
{
int num;
B(){
//constructor code;
}
}
2.
class A
{
int num;
A(B obj_B){
//constructor code;
}
}
class B
{
int num;
B(){
//constructor code;
}
}
What I came to know that for uni-directional association following things should be there in a code..(correct me if it is wrong..I just started learning OOAD)
i. class A has object of class B as an attribute.
ii. class B object may be initialized in constructor of class A
Above code snippets satisfy one of the above points, which one of them to choose as uni-directional association?