tags:

views:

77

answers:

1

I have a project I'm working on (http://github.com/lusis/vogeler). One of the goals is to provide swappable persistance and messaging backends. I think I have a workable model in place but wanted to get input from the Python crowd about best practices. You can see the new implementation here:

http://github.com/lusis/vogeler/blob/master/vogeler/db/generic.py

couch2.py is my subclass of generic.

Essentially the generic class provides a common set of interfaces (createdb, usedb, create, update) which call private methods such as _create_db, _use_db and so on.

My expectation is that the database specific stuff will subclass GenericPersistence and override the private methods. Is that considered bad form? Overriding private methods in general feels kind of weird but the end result is that it works. I just want to make sure I'm not breaking some sort of unwritten contract about subclassing in Python.

A: 

I think, by convention, the single underscore is a hint that the attribute is an implementation detail that may be changed in the future. Subclasses should not override or invoke underscored methods, because their presence may not be relied on.

So, I'd change the underscored methods to hooks: _update --> update_hook and ask developers to override the *_hook methods.

unutbu
I guess the reason I went with _method names was to really make it clear that you should be calling this unless you're writing a persistence backend but I like the foo_hook option as well.
lusis
So I refactored to use the hook_ naming convention. Thanks!
lusis