Nov-30-2018, 07:47 AM
Thank you for this quick reply, and sorry for this dumb question.
Btw why the abstract method B for example doesn't care of param ?
Was more expecting
Btw why the abstract method B for example doesn't care of param ?
Was more expecting
@abc.abstractmethod def do_sth(self, nom): """Required Method"""than
@abc.abstractmethod def do_sth(self): """Required Method"""I did update App.py to be
from AStrategyAbstract import A1Strategy,A2Strategy,A3Strategy from BStrategyAbstract import B1Strategy,B2Strategy,B3Strategy from CStrategyAbstract import C1Strategy,C2Strategy,C3Strategy a1_strategy = A1Strategy() a2_strategy = A2Strategy() a3_strategy = A3Strategy() b1_strategy = B1Strategy() b2_strategy = B2Strategy() b3_strategy = B3Strategy() c1_strategy = C1Strategy() c2_strategy = C2Strategy() c3_strategy = C3Strategy() class App(object): def __init__(self, a_strategy, b_strategy, c_strategy): self._a_strategy = a_strategy self._b_strategy = b_strategy self._c_strategy = c_strategy self.name = None def do_sth(self,name): self.name = self._a_strategy.do_sth() self._b_strategy.do_sth(self.name) self._c_strategy.do_sth(self.name) class AApp(App): def __init__(self): super(AApp, self).__init__(a1_strategy, b3_strategy, c2_strategy) def start(self): self.do_sth(self.name) class BApp(App): def __init__(self): super(BApp, self).__init__(a2_strategy, b1_strategy, c2_strategy) def start(self): self.do_sth(self.name) if __name__ == '__main__': myaapp = AApp() myaapp.start() mybapp = BApp() mybapp.start()AStrategyAbstract.py
import abc class AStrategyAbstract(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def do_sth(self): """Required Method""" class A1Strategy(AStrategyAbstract): def do_sth(self): print("A1 Strategy applied") print("Give me your name") name = input() return name class A2Strategy(AStrategyAbstract): def do_sth(self): print("A2 Strategy applied") print("Give me your name") name = input() return name class A3Strategy(AStrategyAbstract): def do_sth(self): print("A3 Strategy applied") print("Give me your name") name = input() return nameBStrategyAbstract.py
import abc class BStrategyAbstract(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def do_sth(self): """Required Method""" class B1Strategy(BStrategyAbstract): def do_sth(self, name): print("B1 Strategy applied {}".format(name)) class B2Strategy(BStrategyAbstract): def do_sth(self, name): print("B2 Strategy applied {}".format(name)) class B3Strategy(BStrategyAbstract): def do_sth(self, name): print("B3 Strategy applied {}".format(name))