I'm currently learning about coupling and dependencies in Java. I've been reading this tutorial and understand that if class1 contains an instance of class2 and if you call a method like exampleMethod(c2)
, this counts as dependency between class1 and class2. However, I am unsure about the examples below. Can anyone give me some clarification?
Assuming that we are inside class1 (which contains class2 c2
):
If class1 calls a method defined in class2 (c2.aMethod()
for example), does this count as a dependency/coupling between class1 and class2?
Does calling c2.someSetterMethod(argument)
count as dependency/coupling between class1 and class2?
Does calling c2.repaint()
within class1 count as a dependency?
The fact that class1 contains a reference to an instance of class2 suffices to say that class1 depends on class2. In all of your 3 examples you need a reference to class2 in order to call its methods. This only increases the need for dependency in your class1 but not the dependency itself.
Please read http://depfind.sourceforge.net/Manual.html#Dependencies as mentioned in my answer to your previous question: https://stackoverflow.com/a/21689495/1659599.