Re: Globals or objects?
- From: tinnews@xxxxxxxxxx
- Date: 21 Feb 2008 13:41:22 GMT
Steve Holden <steve@xxxxxxxxxxxxx> wrote:
MartinRinehart@xxxxxxxxx wrote:I think the OP was asking rather how the Object is any different from
I had a global variable holding a count. One source Google found
suggested that I wouldn't need the global if I used an object. So I
created a Singleton class that now holds the former global as an
instance attribute. Bye, bye, global.
But later I thought about it. I cannot see a single advantage to the
object approach. Am I missing something? Or was the original global a
better, cleaner solution to the "I need a value I can read/write from
several places" problem?
Look up "coupling" and "cohesion" in Wikipedia or similar, and you will
find out that global variables are bad because they introduce tight
coupling between different pieces of functionality in your code.
the global if it's simply used as a wrapper for a single value.
In usage, philosophy or whatever it's effectively identical and
introduces all the same problems as a global does, it just gives it a
longer name.
Objects only become useful when the encapsulate more than on thing.
--
Chris Green
.
- References:
- Globals or objects?
- From: MartinRinehart
- Re: Globals or objects?
- From: Steve Holden
- Globals or objects?
- Prev by Date: understaning "self"
- Next by Date: Re: Tkinter OSX and "lift"
- Previous by thread: Re: Globals or objects?
- Next by thread: Re: Globals or objects?
- Index(es):