I am trying to draw a class diagram and am confused regarding the association relationship to be used in the scenario similar to the one below.
Interface SampleInterface{
void sampleMethod();
}
class SampleInterfaceImpl implements SampleInterface{
public void sampleMethod(){
}
}
class launcher{
private SampleInterface interfaceImpl;
public void setInterfaceImpl(SampleInterface interfaceImpl)
{
this.setInterfaceImpl = interfaceImpl;
}
}
In the above example Launcher class has a state variable interfaceImpl of type SampleInterface . I am passing initializing the Launcher class by using Spring setter injection to pass an implementation of SampleInterface as a bean . The scope of the bean is singleton.
The same bean is passed to other objects as well through spring.
My Doubts :
Is this relationship a composition or aggregation ? (Since the same bean is passed everywhere it is required and it is in singleton scope)
Can we represent the relationship as aggregation or composition when the state variable is an Interface type rather than a class type ? Or should i just represent it as an association ?
Thanks
You should not care too much about composition/aggregation unless it's for some reason essential. This is the case if you explicitly want to show some objects lifetime depending on other objects lifetime.
So in your case you should simply use an association. This would in any case not be wrong. Connectors have a hierarchy regarding their semantics. Dependency is lowest level. Association is above. And aggregation/composition above association. Using a lower level is never wrong. It just leaves a bit more freedom in the interpretation how the objects relate.