Is it better to use class variables or pass parameters?

Steve Holden steve at holdenweb.com
Thu Mar 16 03:48:40 EST 2006


Derek Basch wrote:
> So, if I am understanding what everyone is saying here. I should do my
> best to distinguish between values that are part of the "state" of an
> object and values that are more disposable and can change for each
> computation of a value. So if I create an instance of a "wallet" class
> and the color of the wallet is "red". The "red" value would be ideal as
> a class variable as it is tied to the state of that wallet instance.

Nope. Technically that would be an *instance* variable - each wallet 
instance can have a different colour. [This may be what you mean in 
whcih case please regard this as correcting your language, not your 
thinking. Class variables are available, and are normally single values 
share among all instances of a class.].

> However, if the wallet class contains a function to compute the tax on
> a purchased item, the purchase price would be a good example of a
> passed parameter value. Am I on the right track?
> 
Yes, that would be correct.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd                 www.holdenweb.com
Love me, love my blog         holdenweb.blogspot.com




More information about the Python-list mailing list