Closed chiamyunqing closed 4 years ago
Or would that be wrong since the textbook states that "In the context of OOP associations, a dependency is a need for one class to depend on another without having a direct association with it." and since there is already an association between Activity class and Watcher class, they cannot have a dependency?
That's correct. Strictly speaking, there is a dependency but no point showing it in the diagram because an association already exists. Showing a dependency in the diagram doesn't add value because an association is a dependency and more. An easier way to remember is, the solid arrow already contains a dashed arrow inside it.
To give an analogy, there's no point saying "I'm related to X" after saying "I'm the daughter of X" (the latter already implies the former).
For the following question from Practice Quiz Part 3, there is no dependency from Activity to Watcher because the watcher is simply a parameter in the function watch() of the Activity class.
To clarify, this is incorrect. A parameter may not necessarily indicate an association but it certainly indicates a dependency.
Just wanted to clarify about dependencies.
For the following question from Practice Quiz Part 3, there is no dependency from Activity to Watcher because the watcher is simply a parameter in the function watch() of the Activity class.
void watch(Watcher w) {..}
However, am I right to say that if the code for function watch() in Activity class is as follows then there will be a dependency from Activity to Watcher?
void watch(Watcher w) { w.callAFunctionFromWatcher(); ... }
Or would that be wrong since the textbook states that "In the context of OOP associations, a dependency is a need for one class to depend on another without having a direct association with it." and since there is already an association between Activity class and Watcher class, they cannot have a dependency?
Thanks in advance!