麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Python > 正文

python優(yōu)雅實(shí)現(xiàn)策略模式

2019-11-11 07:53:08
字體:
供稿:網(wǎng)友

優(yōu)雅實(shí)現(xiàn)策略模式; 在awesome-python上有一個(gè)關(guān)于模式設(shè)計(jì)的包,對(duì)包中的代碼做了一點(diǎn)修改。

# -*- coding: utf-8 -*-"""http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern -written-in-python-the-sample-in-wikipediaIn most of other languages Strategy pattern is implemented via creating somebase strategy interface/abstract class and subclassing it with a number ofconcrete strategies (as we can see athttp://en.wikipedia.org/wiki/Strategy_pattern), however Python supportshigher-order functions and allows us to have only one class and injectfunctions into it's instances, as shown in this example."""import typesclass StrategyExample:    def __init__(self, func=None):        self.name = 'Strategy Example 0'        if func is not None:            self.select(func)    def __call__(self, arg=''):   # special method for execute        self.execute()    def execute(self):        

輸出為

nothingnothingStrategy Example 1 from execute 1Strategy Example 2 from execute 2Strategy Example 2 from execute 1Strategy Example x from execute 2


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产91丝袜在线播放 | 久久免费综合视频 | 欧美高清在线精品一区二区不卡 | 精品一区二区三区免费看 | 亚洲日本高清 | 精品国产呦系列在线看 | 欧美爱爱视频 | 免费一及片 | 久久91亚洲人成电影网站 | 激情夜色 | 国产www免费| 日韩理论电影网 | 97中文字幕第一一一页 | 中文字幕免费播放 | 日本xxxx色视频在线观看免费, | 一级做a爱片性色毛片 | 黄色香蕉视频 | 4480午夜| 北京一级毛片 | 麻豆传传媒久久久爱 | 免费啪视频在线观看 | 国产精品欧美久久久久一区二区 | 一级黄色影院 | 欧美日韩中文字幕在线视频 | 久国久产久精永久网页 | 欧美 日韩 中文 | 国产做爰全免费的视频黑人 | 亚洲乱操 | 亚洲乱妇19p | 国产精品久久久久久久久久 | 亚洲二区三区在线 | 国产精品久久久久久久成人午夜 | wwwxxx免费视频| 久草在线视频在线 | 欧美性生活网站 | 91成人在线网站 | 牛牛视频在线 | 久久久日韩精品一区二区三区 | 国产精品久久久久久影视 | 欧美精品一区二区视频 | 久久人人人 |