class variables and class methods

K

krishnapostings

I have a class whose job is to serve several other objects, this
object is in a module 'M1', let's say it writes logs, no matter who
calls it, (once it started writing to a file) it must continue writing
to the same file, the file pointer could be a class variable here and
there is also no need to have object methods, all could be class
methods (my understanding of benefits between class and objects is not
good, see below).
1. Should I have one object 'O1' that serves all i.e., no class
variables, class methods, if so, since this class is in a module
('M1'), and in several other modules this module is imported, should I
have in this 'M1' a global variable 'g' (let's call it module
variable) that points to the object, thus whoever wants to use the
object must import the module and through this module variable get
pointer to the object, thus no matter how many times who ever imports
there is only one object serving everyone as the object referred
through 'g' is in one namespace 'M1'.
This doesn't look elegant.
2. Should I have a class which does the job, and the class has a class
variable 'cv' which should point to the file pointer and the methods
should all be class methods. Now, from resource point of view, how
much is the benefit of making a method class method? how about in this
case where there are no object variables? Maybe the answers to these
questions answers the following question, Is there a case when we
would want to have a class with no object variables and all methods
class methods.

Thanks,
Krishna.
 
A

Aahz

I have a class whose job is to serve several other objects, [...]

Sorry, I'm finding it difficult to understand what you want. It looks
to me that you're confusing "object" and "instance", and I think you're
also confusing "variable" and "attribute". You might find it helpful to
read the following URLs and then re-post with new phrasing:

http://docs.python.org/tutorial/classes.html
http://starship.python.net/crew/mwh/hacks/objectthink.html
http://effbot.org/zone/python-objects.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top