Created
August 1, 2017 15:21
-
-
Save geekKeen/6681d21adf53f79aeba2250ac7a6f582 to your computer and use it in GitHub Desktop.
遇到初始化时碰到的一些问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(object): | |
def __init__(self, **config): | |
self._config = {} | |
self.make_config(config) | |
def make_config(config): | |
self._config.update(config) | |
class B(object): | |
def __init__(self, **config): | |
self._config = {} | |
self._config['a'] = config['a'] | |
... |
仔细思考后觉得这种写法,也没什么优势, 主要是 mail-sys 中 gethtml 函数没有符合单一职责的原则,函数调用有副作用, 直接插了数据,应该避免
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A 写法的好处:
make_config
就可以了; 第二种写法就没有灵活性, 因为__init__是一定会跑的,值也就没办法改变了