Examples of this article for you to share the Python strategy model code for your reference, the specific contents are as follows
""
Policy Mode ""
Import Types
class Strategyexample:
def __init__ (self, func=none):
self.name = ' Policy example 0 '
if Func is not None: ' ""
for instance-bound methods, does not affect other instances "" "
Self.execute = types. Methodtype (func, self)
def execute (self):
print (self.name)
def execute_replacement1 (self):
Print (Self.name + ' from execution 1 ')
def Execute_replacement2 (self):
print (Self.name + ' from Execution 2 ')
if __name__ = = ' __ Main__ ':
strat0 = strategyexample ()
strat1 = Strategyexample (execute_replacement1)
strat1.name = ' Policy Example 1 '
strat2 = strategyexample (execute_replacement2)
strat2.name = ' Policy Example 2 '
strat0.execute ()
Strat1.execute ()
Strat2.execute ()
Run the results as shown in figure:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.