I have just been reading momoko docs, and came across the following class:
class BaseHandler(RequestHandler):
@property
def db(self):
return self.application.db
Every time we want to access db attribute of base_handler instance of BaseHandler, the db(self) will be called, returning self.application.db.
What is the advantage of this code over the following?
class BaseHandler(RequestHandler):
def __init__(self):
self.db = self.application.db
This will bind instance variable db to self.application.db.
I understand that the former approach will avoid us of having self.db in each instance. On the other hand, self.application.db has extra attribute resolution step (extra .).
Are there any advantages of the former approach that I don't see?