Search code examples
javaandroidandroid-intentencapsulation

Is Passing Intent Extras Between Activities Bad Style?


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?


Solution

  • Encapsulation, as one of the whale of Object-Oriented paradigm, assumes that you free programmers, who will use your class in future, from the necessity to know how does your component built inside and what complex aspects does it hold, carrying out this information to comfortable and clear programming interface (in the best cases).

    Intent model was developed so, that it assumes interaction between main components of operating system, especially Activitys, and also it assumes that you need to accompany your intents with some concrete information such as kind of ACTIONs you want to perform, a CATEGORY of your intent and some set of DATA that need to implement your intents. So this is convenient model in such kind of interactions.

    At the same time, using some shared class between activities when there is a ready solution for that, is rather irrelevant approach, IMO.