1

It seems to me that passing extras via Intent calls is a violation of encapsulation, since classes are directly communicating with one another. That being said, the only viable alternative to this that I have found is setting a variable in some shared class and just having each activity pull data from it - part of me, however, can't help feeling that this isn't a great design choice either. Can someone shed some light on this?

4

2 回答 2

0

不是,你最终会需要它。通常我在活动之间传递最少的信息,然后在启动的活动的 onCreate() 中检查大数据。

于 2012-12-02T17:52:58.367 回答
0

封装,作为面向对象范式的鲸鱼之一,假设您让将来会使用您的类的程序员从了解组件内部如何构建以及它包含哪些复杂方面的必要性中解放出来,执行这些信息舒适和清晰的编程界面(在最好的情况下)。

Intent模型是这样开发的,它假设操作系统的主要组件之间的交互,尤其是Activitys,并且它还假设您需要将一些具体信息伴随您的意图,例如ACTION您想要执行的 s 的种类、CATEGORY您的意图的 a 和一些一组DATA实现您的意图的需要。因此,这是此类交互中的便捷模型。

同时,当有现成的解决方案时,在活动之间使用一些共享类是相当不相关的方法,IMO。

于 2012-12-02T18:11:33.097 回答