In working with python for the first time, I've found that I end up writing multiple classes in the same file, which is opposed to other languages like Java, which uses one file per class.
Usually, these classes are made up of 1 abstract base class, with 1-2 concrete implementations who's use varies slightly. I've posted one such file below:
class Logger(object):
def __init__(self, path, fileName):
self.logFile = open(path + '/' + filename, 'w+')
self.logFile.seek(0, 2)
def log(self, stringtoLog):
self.logFile.write(stringToLog)
def __del__(self):
self.logFile.close()
class TestLogger(Logger):
def __init__(self, serialNumber):
Logger.__init__('/tests/ModuleName', serialNumber):
def readStatusLine(self):
self.logFile.seek(0,0)
statusLine = self.logFile.readLine()
self.logFile.seek(0,2)
return StatusLine
def modifyStatusLine(self, newStatusLine):
self.logFile.seek(0,0)
self.logFile.write(newStatusLine)
self.logFile.seek(0,2)
class GenericLogger(Logger):
def __init__(self, fileName):
Logger.__init__('/tests/GPIO', fileName):
def logGPIOError(self, errorCode):
self.logFile.write(str(errorCode))
As seen above, I have a Logger
base class, with a couple of implementation differences below that.
The Question: Is this standard for python, or for any language? What problems could arise from using this implementation if any?
Please note: I'm not really looking for guidance on this specific file, but in a more general sense. What if the classes ended up being 3-5 moderately complex methods? Would it make sense to split them then? Where is the cutoff for saying you should split a file up?