Communication between a widget, a service, and the model (singleton) of an application (MVC like architecture)

I got a complex question involving many different components of an application. I hope to be clear enough. In my app, the application object, a singleton, provides a model (singleton too) to many activities. The main activity, presents a list of timed data to the user. These data come from the model. I also have a widget and I want it to : - update when timed data is updated from within the model (via the GUI) - as time passes, update to only display the 2 first timed data of the list, removing the ones that are now obsolete. To reach the second objective, I designed a service that asks the model to get some data, and uses timers to wakeup after the first data expired, and remove it from the list then sends a broadcast to the widget with some data in intent, that the widget will display. This works fine. But I also want the widget to update as soon as data changes in the model (not because time passes, but because of the user asking for some other data through the GUI). But, and here is my problem: how can the model tell the widget to update? Everything is in place for the service to update the widget but the engine *can not* know *if* there is a widget. I don't want the model to call the service as maybe there is no widget and no need to have an additional process for the service. How can this interaction be redesigned elegantly? I am really missing something here.

以上就是Communication between a widget, a service, and the model (singleton) of an application (MVC like architecture)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准