The correct way to create an abstraction layer in python

I have a project I'm working on (http://github.com/lusis/vogeler). One of the goals is to provide support with backup and messaging capabilities. I think I have a workable model, but I wanted to get the best practices from the Python crowd. Here you can see the new implementation:

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

couch2.py is my subclass of general.

Essentially, a common class provides a common set of interfaces (createdb, usedb, create, update) that invoke private methods such as _create_db, _use_db, etc.

I expect database-specific stuff to be subclassed by GenericPersistence and override private methods. Is this considered a bad form? Overriding private methods in general seems strange, but the end result is that it works. I just want to make sure I'm not breaking some unwritten subclass contract in Python.

+3
source share
1 answer

I think that, by convention, one underline is a hint that the attribute is an implementation detail that may be changed in the future. Subclasses should not override or refer to underlined methods, since their presence cannot be relied on.

, : _updateupdate_hook * _hook.

0

Source: https://habr.com/ru/post/1766970/


All Articles