Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

模块间页面跳转没问题,如果单纯的数据流转呢? #56

Open
hydyy opened this issue Nov 26, 2017 · 5 comments
Open

模块间页面跳转没问题,如果单纯的数据流转呢? #56

hydyy opened this issue Nov 26, 2017 · 5 comments

Comments

@hydyy
Copy link

hydyy commented Nov 26, 2017

比如说 B 模块向 A 模块提供一个数据获取获取方法 getData(), A 模块怎么去拿呢?

就是说不涉及到页面流转,只是单纯的数据流转。

我刚想了下,充分解耦之后,理论上应该让 A B 之间互相都不知道对方,页面跳转解决了,单纯数据交互呢?
有什么建议吗?

@hao-feng
Copy link
Contributor

hao-feng commented Dec 1, 2017

是的,目前FRDIntent主要用于页面间的跳转。对于单纯的数据交互,不知道自带的NSNotificationCenter能否满足你的需求?

@hydyy
Copy link
Author

hydyy commented Dec 1, 2017

用其他办法是可以解决,但是不够优雅,其实支持起来应该不是很困难,你们并不考虑吗?

@bigyelow
Copy link
Contributor

bigyelow commented Dec 1, 2017

@hydyy 能说下具体的例子吗?在什么场景下需要获取哪种类型的数据,需要以哪种方式(推、拉)获取。在解耦的情况下又要获取信息、数据,一般的观察者模式应该就可以,比如 @hao-feng 说的 NSNotificationCenter 就是一直典型的实现。

@lincode
Copy link
Contributor

lincode commented Dec 1, 2017

Objective-C 中一般是用 delegate 实现这个需求的。让 delegate 返回一部分数据,或者做一部分事情。但还是要依赖一个 protocol。

用 intent 做这个事情是主动获取数据。并可以解耦更彻底。Android 的 intent 确实实现了这个功能。

我们没这么做是因为实现库时这个需求并不强烈。现在也许可以考虑一下。看看如何应用在douban app 中,如果确实比现在更好,有收益,我们就有动力做这件事。

@hydyy
Copy link
Author

hydyy commented Dec 3, 2017

@bigyelow 比如 用户模块对外提供获取提供获取用户信息的接口,其他模块直接去拿数据而不需要关心这个数据怎么来的,谁给的,只要需要去拿就好了。 彻底隐藏这个数据的提供者,如果是 delegate 那其实还是做了一层关系,而我不需要这个关系,NSNotificationCenter 是可以解决这个问题,但是并不优雅,还是需要去写不少的辅助代码,而且要维护 key

其实就跟注册一个 api 一样,我只是想拿数据

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants