observer pattern example refactored