I’m trying to understand one of uml test questions. The associations are different between base and inherited classes, but do inherited classes also inherit the association between base classes, I mean, do inherited classes actually have two associations?
I also have different statements, from which I need to choose the correct one. The right answer is A, but I don’t understand why A is correct and other are not, so if it is possible, please explain every statement.
A) An instance of the ConcreteSubject class might have a reference to zero or more objects of the Observer type.
B) Each instance of the Observer class has a reference to exactly one instance of the Subject class.
C) Each instance of the Subject class has a reference to exactly one instance of the Observer class.
D) An instance of the ConcreteSubject class cannot have any reference to an instance of any other class.
E) An instance of the ConcreteObserver class might have a reference to zero or more instances of the ConcreteSubject class.
Thank you!
[This question and answer hopefully creates some pressure on universty teachers to care about the quality of their exam/quiz questions.]
First, it is important to note that the class diagram has several flaws. The role names "subject" and "object" are at the wrong (opposite) association end. Then, as you have wondered, the subject-objects association has been duplicated, since it is inherited.
Concerning the questions, both answers A and B are correct, while all others are wrong. This follows directly from reading the multiplicity constraints of the one-to-many subject-objects association.
Btw, the wording of answer options B and C is kind of flawed: it may be confusing to say "each instance of the Observer (or Subject) class", since these classes are abstract (visualized by names in italics), which implies that they do not have their own (direct) instances. However, in a general sense, one can say that they do have instances, namely all instances of their concrete subclasses. Therefore, these two answer options are confusing. But it is an important fairness requirement for any kind of exam not to use confusing questions.
I guess that your teacher considers answer B as wrong because it is about instances of the abstract classes Observer and Subject. However, in its current form, answer B is correct. It would only be incorrect, if it would be reworded as "each direct instance of the Observer (or Subject) class".
Answer C is incorrect because an instance of the Subject class may have no link to any Observer (this is implied by the 0 in the 0..*
multiplicity expression).
Answer D is incorrect because the model does not contain any such constraint (which, btw, doesn't make any sense).
Answer E is incorrect because it contradicts the multiplicity constraint that any observer must observe exactly one subject, expressed by the multiplicity expression 1
.