On Wed, Mar 9, 2011 at 4:30 PM, Kenny Riddile <[email protected]> wrote:

> Assuming the singleton is modifiable via its interface, then for all
> intents and purposes, yes, they are.


Again, no.

Singleton is a design pattern whose purpose is to simplify and control
access to a an object for which there is and will only be one instance of.
This instance is set once and used throughout. It does not vary or change.
It is not variable.

Of course you can change the *state* of the singleton object, if that's what
you mean by "modifiable", but if you change the *value* of the object
itself, as one would do with global *variables*, it is no longer a
singleton.

Even in the sense that the singleton state is modifiable, the whole point of
the singleton is to provide an interface through which this globally
accessible object, and its state, is manipulated. There is controlled
access. This is not the case with your run-of-mill, freely accessible global
variable.

On Wed, Mar 9, 2011 at 6:11 PM, David Williams <[email protected]
> wrote:

> Ok, trying to do this but struggling.
>
> I created a class as follows:
>

If all you're doing is defining some *constants* that are not going to
change, extending Application is way overkill. Especially since casting up
to your Application type every time you need something makes your code
horrendous to look at.

You can just do this:

class Constants
{
 public static final String KEY = "MyKey";
}

Then do Constants.Key where you need it. Done.

On Wed, Mar 9, 2011 at 6:11 PM, David Williams <[email protected]
> wrote:

> Sorry, this is just my lack of knowledge on Java here.  I was hoping it was
> something like globalVars.getApiKey(), but that doesn't seem to work.


I highly recommend you brush up on Java, reviewing static and instance level
access of functions and data in particular.

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

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

Reply via email to