Re: [SQLObject] Using SQLObjects as Abstract Classes
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Brad B. <br...@bb...> - 2003-07-25 13:21:05
|
On Thu, Jul 24, 2003 at 08:57:19PM -0500, Ian Bicking wrote: > On Thu, 2003-07-24 at 14:42, Brad Bollenbach wrote: > > Hi all, > > > > How can I use an SQLObject-derived class as an abstract base class? > > Hmm... I'm not exactly clear what an abstract base class is. Is there a > particular problem you are trying to solve? An abstract base class is a class that's not intended to be directly instantiated, instead defining methods that are intended to be overridden in derived classes. The problem I'm trying to solve is a web monitoring system: MonitorBase | | | | | -> StatusMonitor | --> KeywordMonitor ----> MD5ChecksumMonitor So, I want to be able to do something like (untested code): class MonitorBase(SQLObject): """I'm the base class from which all monitors shall be derived. """ created_date = DateTimeCol(notNone = True) last_run_date = DateTimeCol(notNone = True) active = IntCol() ... def doMonitorCheck(self): """Run the check for this monitor.""" raise NotImplementedError("doMonitorCheck is an abstract method.") class StatusMonitor(MonitorBase): """I monitor websites for the 200 OK status.""" def doMonitorCheck(self): ...logic to check for 200 OK... Except this breaks, because any property access on StatusMonitor tries to look for a table called status_monitor. Unless I specify _table = 'monitor' in every derived class, which seems a bit clunky. What would make sense here? Am I approaching this incorrectly or should there be some way of marking SQLObject classes as abstract? It seems to me that if SQLObject wants to support truly transparent persistence then it should allow me to layout my classes without getting in the way (or getting clunky). -- Brad Bollenbach BBnet.ca |