我应该在Python __init__中使用DAO对象吗?

时间:2018-08-18 21:16:59

标签: python class object instance dao

在python中,这更好:

class MyAPI:

    def __init__(self):
       self.dao = MyDAO()

    def getsomething(self):
       something = self.dao.grabSomething()
       newsomething = operateon(something)
       return newsomething

    def getsomethingelse()
       somethingelse = self.dao.grabSomethingElse()
       newsomethingelse = operateon(somethingelse)
       return newsomethingelse

OR

class MyAPI:

    def getsomething(self):
       dao = MyDAO()
       something = dao.grabSomething()
       newsomething = operateon(something)
       return newsomething

    def getsomethingelse()
       dao = MyDAO()
       somethingelse = dao.grabSomethingElse()
       newsomethingelse = operateon(somethingelse)
       return newsomethingelse

我是来自java spring背景的完整python noob,我真的想了解这里的区别。

0 个答案:

没有答案