假设我有一个代表某个接口的基类
class Parser(object):
__metaclass__ = ABCMeta
@abstractmethod
def _parse(self, text):
"""Internal interface. This is somethig a potential
user must implement for his own implementation of Parser"""
pass
def add_quotes(self, text):
"""some postprocessing. Say, every parser should have quotes"""
# ...
def parse(self, text):
"""External interface. Whoever uses children of Parser will
use this method"""
return self.add_quotes(self._parse(text))
对于“内部”API使用私有方法是否可以(即让用户覆盖接口实现的私有方法)和外部使用的常规方法?这看起来有点奇怪......我看到了几种替代方法,但不知道哪一种更好:
preparse
和parse