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 19:29:20
|
On Fri, Jul 25, 2003 at 01:19:02PM -0500, Ian Bicking wrote: > On Fri, 2003-07-25 at 12:27, Brad Bollenbach wrote: > > > If you have that class layout, you are supposing that there will be > > > other subclasses of Monitor. However, each of these subclasses must be > > > a separate table, or great confusion will ensue. > > > > There will only be a single monitor table. Monitors store a common set > > of properties. The only thing that's different is how they behave when > > you say "do your monitor check". > > Then make that into a multiple-class object, Checker. Like: > > class Checker(object): > def __init__(self, monitor): > self.monitor = monitor > def check(self): > assert 0, "Subclass responsibility" > class HTTPChecker(Checker): > def check(self): ... > class MD5HTTPChecker(HTTPChecker): > def check(self): ... > > checkers = {'http': HTTPChecker, 'md5': MD5HTTPChecker} > > class Monitor(SQLObject): > monitorType = StringCol(length=10) > def _get_checker(self): > return checkers[self.monitorType](self) > > > Voila! Composition beats inheritance! Indeed, this looks like the best way to do it (whilst avoiding any ugly hacks). Thanks. :) -- Brad Bollenbach BBnet.ca |