I've recently seen quite a bit of the following pattern in Python:
class Foo: pass
class Bar:
foo_class = Foo
def __init__(self):
self.foo = self.foo_class()
As I understand, the Bar class first creates a reference to the Foo class as a class variable foo_class and then creates the instance of Foo in __init__. Is there any advantages of it instead of just instantiating Foo directly in __init__?
class Foo: pass
class Bar:
def __init__(self):
self.foo = Foo()
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)