suppose library i'm using implements class
class base(object): def __init__(self, private_api_args): ...
it's meant instantiated via
def factory(public_api_args): """ returns base object """ ...
i'd extend base
class adding couple of methods it:
class derived(base): def foo(self): ... def bar(self): ...
is possible initialize derived
without calling private api though?
in other words, should replacement factory
function?
if not have access private api, can following thing:
class base(object): def __init__(self, private_api_args): ... def factory(public_api_args): """ returns base object """ # create base object private api methods return base_object class derived(object): def __init__(self, public_api_args): # indirect access private api method of base object class self.base_object = factory(public_api_args) def foo(self): ... def bar(self): ...
and in main script:
#!/usr/bin/python3 # create derivate object public api args derived_object = derived(public_api_args) # call private api methods derived_object.base_object.method() # call method same object derived_object.foo() derived_object.bar()
Comments
Post a Comment