Inheritance in SQLObject
There's a debate going on about the best way to support inheritance in SQLObject. Better to have this discussion now than never; there is demand for this feature, but there's still no consensus on the best way to do it.
Based on a patch initially offered by Daniel Savard, Oleg Broytmann started last November and maintained a private inheritance branch, and got it working with some patches against the current trunk version. The approach is reminiscent of pure OO inheritance; you can define the base classes in SQLObject, and inherit new classes from them. There is some documentation about inheritance in the branch itself. For example:
Ian Bicking offered this week a counterproposal, which is based on the relational interpretation of inheritance.
The difference is subtle, but important. In Oleg's branch the child class is a descendent of the parent class, in pure OO terms. The resulting database schema contains two tables that are joined to build the child class implicitly. On the other hand, on Ian's proposal, two tables are explicitly created; all that the developer gets is some synctatic suger to simplify the declaration of the relationship between the parent and child classes.
For some reason, I like Ian's proposal better. It's more explicit, and it does not involve any magic or surprise as for the actual implementation. Also, porting between the two versions seems to be relatively easy. I'd like to see it implemented. On the other hand, Oleg's implementation had one interesting feature: it actually mapped, in transparent way, all the attributes of the parent class as attributes of the child class. I don't know if Ian intend to keep this behavior, that may have a lot of caveats of its own. But it seems logical, and makes acessing attributes on the child class easier, and more naturally related to the inheritance relationship, as shown in this example:
I had also missed an important semantic difference between the proposals. In the original proposal, a select done on the child table can return heterogeneous members; for example, a select on Employee by firstName may return both Person and Employee objects. Again, thanks to Ian for kindly pointing that out.
Based on a patch initially offered by Daniel Savard, Oleg Broytmann started last November and maintained a private inheritance branch, and got it working with some patches against the current trunk version. The approach is reminiscent of pure OO inheritance; you can define the base classes in SQLObject, and inherit new classes from them. There is some documentation about inheritance in the branch itself. For example:
class Person(SQLObject):
_inheritable = 1 # I want this class to be inherited
firstName = StringCol()
lastName = StringCol()
class Employee(Person):
_inheritable = 0 # If I don't want this class to be inherited
position = StringCol()
Ian Bicking offered this week a counterproposal, which is based on the relational interpretation of inheritance.
class Person(SQLObject):
firstName = StringCol()
lastName = StringCol()
class Employee(JoinedSQLObject):
_parent = 'Person'
position = StringCol()
The difference is subtle, but important. In Oleg's branch the child class is a descendent of the parent class, in pure OO terms. The resulting database schema contains two tables that are joined to build the child class implicitly. On the other hand, on Ian's proposal, two tables are explicitly created; all that the developer gets is some synctatic suger to simplify the declaration of the relationship between the parent and child classes.
For some reason, I like Ian's proposal better. It's more explicit, and it does not involve any magic or surprise as for the actual implementation. Also, porting between the two versions seems to be relatively easy. I'd like to see it implemented. On the other hand, Oleg's implementation had one interesting feature: it actually mapped, in transparent way, all the attributes of the parent class as attributes of the child class. I don't know if Ian intend to keep this behavior, that may have a lot of caveats of its own. But it seems logical, and makes acessing attributes on the child class easier, and more naturally related to the inheritance relationship, as shown in this example:
newemployee = Employee(firstName='John',
lastName='Smith',
position='Hardcore coder')
Errata
I had originally mistakenly attributed the inheritance patch to Oleg Broytmann. Ian Bicking has kindly pointed me to Daniel Savard as the original author (Thanks Ian!).I had also missed an important semantic difference between the proposals. In the original proposal, a select done on the child table can return heterogeneous members; for example, a select on Employee by firstName may return both Person and Employee objects. Again, thanks to Ian for kindly pointing that out.
5 Comments:
At January 21, 2005 at 4:33 PM, Ian Bicking said…
It was actually Daniel Savard who wrote the patch, and Oleg brought it up to date and has been keeping it in sync with the trunk.
My proposal (which was just a strawman) was semantically quite different, in that you still wouldn't get heterogeneous lists -- with Daniel's patch you could get a bunch of Person *or* Employee objects from a select, while with _parent you'd just get back Person object, who would have the Employee attributes folded in; you'd get NULLs on those attributes if you selected a person who wasn't an employee, as opposed to being able to check the type, or getting AttributeErrors.
At March 4, 2016 at 8:32 PM, Anonymous said…
ninest123 16.03
prada outlet, nike outlet, longchamp outlet, burberry outlet, gucci handbags, ralph lauren polo, cheap jordans, louis vuitton outlet, louis vuitton outlet online, oakley sunglasses, uggs on sale, louis vuitton outlet, tiffany jewelry, replica watches, ralph lauren outlet, michael kors outlet, longchamp outlet, cheap oakley sunglasses, ray ban sunglasses, michael kors handbags, replica watches, michael kors outlet online, oakley sunglasses, uggs on sale, louboutin shoes, christian louboutin, ray ban sunglasses, uggs outlet, nike free, christian louboutin, uggs outlet, tiffany jewelry, nike air max, oakley sunglasses, longchamp bags, uggs on sale, michael kors outlet online, michael kors outlet online, nike air max, louis vuitton handbags, oakley sunglasses, louis vuitton, ray ban sunglasses, louboutin uk, michael kors, tory burch outlet, burberry factory outlet, prada handbags
At April 29, 2016 at 12:32 AM, chenlili said…
2016-4-29 xiaobao
michael kors
nfl jerseys
fitflops sale clearance
michael kors bags
toms shoes
true religion jeans
nike nfl jerseys
coach factory outlet
ray ban wayfarer
timberland boots
cheap jerseys
michael kors outlet
louis vuitton outlet
michael kors outlet online
jordan retro 3
michael kors outlet
michael kors handbags
oakley sunglasses wholesale
nike uk
michael kors outlet
michael kors handbags
gucci outlet
ray ban uk
nike roshe flyknit
kate spade handbags
longchamp bags
michael kors outlet
nike air force
nike uk
air jordan pas cher
coach outlet
christian louboutin sale
toms
coach outlet
polo ralph lauren
cheap jordans
louis vuitton outlet
true religion shorts
ray ban sunglasses
At December 14, 2016 at 9:45 PM, chenlina said…
air jordans
ugg boots outlet
louis vuitton outlet
moncler jackets
toms shoes
canada goose jackets
kate spade
moncler
coach outlet
ray ban sunglasses
chenlina20161215
At March 7, 2017 at 4:32 AM, Unknown said…
Good write-up
http://www.prokr.net/2016/09/anti-black-ants-7.html
http://www.prokr.net/2016/09/anti-black-ants-6.html
http://www.prokr.net/2016/09/anti-black-ants-5.html
http://www.prokr.net/2016/09/anti-black-ants-4.html
http://www.prokr.net/2016/09/anti-black-ants-3.html
http://www.prokr.net/2016/09/anti-black-ants-2.html
http://www.prokr.net/2016/09/anti-black-ants.html
Post a Comment
<< Home