search

Home  >  Q&A  >  body text

android - 下通过消息方式实现界面解耦有什么优势

模块和界面解耦是App规模成长到一定规模后必须要走的一条路
对于解耦的原理,现在貌似通过消息机制进行相互调用很流行

始终没想明白,通过消息方式解耦,和传统的通过抽象ID(比如一个URL,一个URL对应一个界面)进行调用有什么优势吗?

伊谢尔伦伊谢尔伦2812 days ago711

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:06:45

    1. I think it is similar in your case. If an ID can represent an interface or the call of an interface element
    2. ReactiveCocoa has several classic examples. When elements on an interface have multiple dependencies, ReactiveCocoa’s writing method is still very comfortable. For example, when two events are triggered, an interface will be updated. You We need to write a logic to monitor these two IDs
    3. You don’t need to write callbacks, blocks, etc. when doing various asynchronous things. You can use events directly. Please correct me. It’s not that you don’t need to write logic, but this way seems more direct

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:06:45

    Relatively speaking, the scalability and flexibility of messages are better than the traditional abstract ID. Moreover, the logic related to different interfaces can be controlled within the minimum scope, as long as the corresponding observer or consumer is implemented. Avoid sharing of static objects. Moreover, data exchange between different threads is not prone to exceptions.

    reply
    0
  • Cancelreply