On 3/10/2011 10:41 AM, TreKing wrote:
Hmm, perhaps this is semantics at this point. I don't think a singleton
is "a global", as it's usually a private member that is statically
accessible. However, there is "global access", of course.

If it's a single piece of state that's accessible globally, then to me, it's a global, regardless of the particular syntax or representation.

No, but in terms of clarity, readability, and ease of debugging, there
is a *huge* difference in using a singleton to modify some globally
accessible object versus a "classic global".

To me, the third option of "don't use either one" is almost always better in terms of clarity, readability, and ease of debugging.

Normally, I wholeheartedly agree. However, the Android model and
intricacies of the lifecycle of an Android app present some unique
challenges with regard to managing and passing around objects that are
needed across multiple Activities. So it's not always that simple.
Sometimes, when considering ease and speed of implementation,
readability, and maintainability, a Singleton really is the best option.

I admit, I've only released one Android app of intermediate complexity. It's been my experience on other platforms and languages, that any framework that encourages sections of your code to communicate via mutable global state is fundamentally flawed. I haven't felt encouraged in that manner by Android thus far.

Anyways, this has gotten a bit off-topic from the OP's original question, and for that, I apologize :)

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to