Easy understanding of the policy mode of the python design mode, python Design Mode

Source: Internet
Author: User

Easy understanding of the policy mode of the python design mode, python Design Mode

This article provides examples of the python policy mode code for your reference. The specific content is as follows:

"Policy mode" import typesclass StrategyExample: def _ init _ (self, func = None): self. name = 'policy example 0' if func is not None: "is used to bind methods to the instance, and does not affect other instances" self.exe cute = types. methodType (func, self) def execute (self): print (self. name) def execute_replacement1 (self): print (self. name + 'slave execution 1') def execute_replacement2 (self): print (self. name + 'slave 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 ()

Running result:

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.