Open cth06-Github opened 3 hours ago
I think the Command
pattern is used, and I have the same idea as you for that.
However, I don't really think the Observer
pattern applies here. Referring to your annotation below:
In the textbook, I believe StudentListUi
and StudentStatsUi
are both concrete observers, and the one being observed is the StudentList
. Then, all concrete observers must implement the Observer
interface.
In the context of the question, however, it seems that ActionX
and ActionY
are not the observers but rather the ones being observed. They are observed by only 1 class, which is the History
class.
Since this History
class did not observe the Actions ActionX
and ActionY
by implementing an interface, I believe this doesn't closely match the observer pattern anymore. (History
only manages to keep track of ActionX
and ActionY
via directly having a list of Repeatables
).
Generally, if there was an interface which would have allowed multiple classes that implemented it to keep track of the Action
objects, then perhaps I would be inclined to agree.
I was doing Q1 of AY18/19 Sem 1 Part 2 (see picture below), and the relevant class diagram for that was explained in one of the videos going through drawing class diagrams in Week 8 Topics (specifically, "Drawing class/object diagrams (intermediate) -
Action
,Task
,History
") (it's the same question used). Using that class diagram as the basis, I tried to answer 1b), which asked what design pattern it is.I felt that there are 2 design patterns here: Command pattern and Observer pattern. The image showed how I saw the similarity for both patterns. However, question 1b felt like we can only choose 1 pattern. I was wondering if my analysis went wrong, or that if there are really 2 design patterns, is there one that is more prominent than the other? (Which I don't see it now). Or it will be ok to just state any of the correct design patterns?