Textbook question about OOD with odd answer

Started by
4 comments, last by Hodgman 11 years ago

I'm currently taking a AP programming course, and since I know most of the material already, I sometimes assist my teacher. The class is studying Object Oriented Progamming and Design in Java. My teacher and I were reviewing questions from the textbook which the class was working on, when we spotted answer that looked suspicious. I don't have the question with me right now, but it was something like this:

"What relationship tends to indicate a dependency?

a) IS_A

b) HAS_A

c) KNOWS_ABOUT

answer: c"

I was a bit confused about this answer beacuse I have never heard of a KNOWS_ABOUT relationship before this. I am aware of the IS_A and HAS_A relationships from the programming book I read when I first started programming. Have you ever heard about the KNOWS_ABOUT relationship, and are we wrong?

Advertisement
That seems like the right answer. Think of it this way, if your code uses a class in a package as a function parameter, you should import the package. The import tells your code about the package, so your code depends on that package and it "knows about" the package. You can't depend on a class if you don't know about it. If you don't store objects of that class type, you don't have a "has a" relationship, and if you don't inherit from that class you don't have an "is a" relationship.

The answer seems right, as SiCrane explained well. I think the confusion is less about "knows about" and more about what "dependency" means.

That said, I don't think I've ever heard the "knows about" relationship described as such, certainly not formally. Out of fairness I'd discount the question unless the course material has explicitly talked about it in those terms, otherwise many students might reasonably assume it to be a red herring. Even then, the question is far from perfect -- both a) and b) take on a dependency as well, and you can only arrive at the right answer by eliminating a) and b) as having gone "too far". Personally, I'm left wanting d) All of the above as a satisfactory answer, but that contradicts that just c) is an adequate answer on its own. If I were the one teaching, I'd probably just eliminate that question.

throw table_exception("(? ???)? ? ???");

The thing is that "is a" and "has a" are subsets of "knows about"; however, "knows about" also includes other types of relationships beyond just "is a" and "has a". For example, if object A has a method that acts upon an unrelated object B (like, say, a bullet dealing damage to an enemy, or an enemy tracking the player's movement), then it has to know about object B even though neither "has a" nor "is a" applies.

Supersets, not subsets ;) +1 anyways

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
I'd answer that as 'all of the above'...
"is a" and "has a" are both instances of "knows about", as are "operates on"/"passed as argument"/"makes use of" etc...
All of these are dependencies, which in my eyes is synonymous with 'knowing about'.

This topic is closed to new replies.

Advertisement