nus-cs2103-AY2425S1 / forum

11 stars 0 forks source link

What's the Design Pattern for AY18/19 Sem 1 Question 1b #918

Open cth06-Github opened 3 hours ago

cth06-Github commented 3 hours ago

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. image

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?

emmannyyy commented 2 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: image 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.