I read a book about the observer pattern. It gives the following example:
Class clock
, with method time()
Class message
, which 3 class inherit from it: Fax, Mail, Memo
.
The application wants to send a message when 12AM arrived.
The book recommends observer pattern. It says that if we add new class: VideoMsg
which extends message, it would affect the implementation of class Clock. But I didn't understand why. The class Clock would hold collection of message
's object, and if we will add a new inherit class, It wouldn't change the clock class.
I would appreciate if someone will explain the example above, or give a better example.