vendredi 29 septembre 2017

Why do some methods belong to the subject/observer interface, while others to the subject/observer concrete subclass?

From Design Pattern by Gang of Four enter image description here

Why are field observers, and methods Attach, Detach and Notify are in the interface Subject, while methods GetState and SetState and field SubjectState are in the concrete subclass ConcreteSubject? Why are the members distributed in the subject interface and concrete subclass as they are?

Why is method Update in the interface Observer, while fields subject and observerState in the concrete subclass ConcreteObserver? Why are the members distributed in the observer interface and concrete subclass as they are?

There doesn't seem to be symmetry between subject and observer. For example, why does field observers belong to interface Subject, while field subject belong to ConcreteObserver?

Thanks.

Aucun commentaire:

Enregistrer un commentaire