nus-cs2103-AY2122S1 / forum

18 stars 2 forks source link

Question about Part 2 of practise exam #420

Closed junghon3709 closed 3 years ago

junghon3709 commented 3 years ago

image

It is mentioned that a1 and a2 are both being watched by UiWidget object u in Part 2 of the practise exam uploaded. So shouldn't a1 and a2 be navigable from u? So shouldn't the arrow be from u to a1 and a2 instead?

yucheng11122017 commented 3 years ago

According to the code, I don't believe there is a reference from the Observer to the Activity. This was kind of the point of the Observer pattern where there is no need for the Observer to have a dependency to Observed (UiWidget in this case), rather the Observed only needed to have a dependency to the Observer interface.

junghon3709 commented 3 years ago

I see, thanks!

damithc commented 3 years ago

According to the code, I don't believe there is a reference from the Observer to the Activity.

Yup, that's correct. Thanks @yucheng11122017

This was kind of the point of the Observer pattern where there is no need for the Observer to have a dependency to Observed (UiWidget in this case), rather the Observed only needed to have a dependency to the Observer interface.

Actually, the point of the patterns is to avoid the Observed class (i.e., Activity) having to know about the Observer class (i.e., UiWidget) and yet to be able to communicate with Observers. In this case, in spite of the a1:Activity -> u:UiWidget navigability, the class Activity is unaware of the UiWidget class (as per the class diagram).