![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
mz5111089
这个作者很懒,什么都没留下…
展开
-
Python 工厂模式
直接上码# -*- coding: utf-8 -*-"""Created on Fri Feb 9 11:03:28 2018@author: mz"""class Factory(object): def Manufacture(self): print("Base products")class ConcreteFactoryA(Factory):...原创 2018-02-09 11:55:58 · 212 阅读 · 0 评论 -
Python 解析器模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 29 19:26:13 2018@author: mz"""class Context(object): def SetContect(self, rhs): self.context = rhs def GetContext(self): ret...原创 2018-03-29 19:58:14 · 392 阅读 · 0 评论 -
Python 命令模式
# -*- coding: utf-8 -*-"""Created on Mon Mar 26 17:17:02 2018@author: mz"""class ICommand(object): def __init__(self, rhs): self.rcv = rhs def Excute(self): passc...原创 2018-03-26 18:51:23 · 331 阅读 · 0 评论 -
Python 代理模式
# -*- coding: utf-8 -*-"""Created on Mon Mar 26 19:17:20 2018@author: mz"""class Person(object): def ShowLove(self): passclass Girl(Person): def ShowLove(self): pass...原创 2018-03-26 19:34:49 · 130 阅读 · 0 评论 -
Python 单例模式
# -*- coding: utf-8 -*-"""Created on Mon Mar 26 19:40:24 2018@author: mz"""import threadingclass Singleton(object): _instance_lock = threading.Lock() def __init__(self): pass...原创 2018-03-27 11:54:44 · 970 阅读 · 0 评论 -
Python 外观模式
# -*- coding: utf-8 -*-"""Created on Tue Mar 27 16:56:43 2018@author: mz"""class Facade(object): def TradeWar(self): a = ASubject() b = BSubject() c = CSubject() ...原创 2018-03-27 17:06:48 · 211 阅读 · 0 评论 -
Python 模板方法
# -*- coding: utf-8 -*-"""Created on Tue Mar 27 17:08:14 2018@author: mz"""class Template(object): def Excute(self): self.ReadyRead() self.ReadyWrite() def Read...原创 2018-03-27 17:14:49 · 295 阅读 · 0 评论 -
Python 观察者模式
# -*- coding: utf-8 -*-"""Created on Wed Mar 28 18:50:47 2018@author: mz"""#observerclass Boss(object): def __init__(self): self.obj = []; def Attach(self, employee): ...原创 2018-03-28 19:40:11 · 168 阅读 · 0 评论 -
Python 原型模式
# -*- coding: utf-8 -*-"""Created on Wed Mar 28 19:41:57 2018@author: mz"""from copy import copy, deepcopyclass Prototype(object): def Clone(self): pass def DeepClone(sel...原创 2018-03-28 20:33:21 · 214 阅读 · 0 评论 -
Python 享元模式
# -*- coding: utf-8 -*-"""Created on Wed Mar 28 20:41:17 2018@author: mz"""class Share(object): def __init__(self): self.d = {} def Attach(self, key, value): if key...原创 2018-03-28 20:55:32 · 170 阅读 · 0 评论 -
Python 建造者模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 29 10:19:38 2018@author: mz"""class Director(object): def Build(self, builder): builder.BuildFloor() builder.BuildWindow...原创 2018-03-29 11:00:20 · 312 阅读 · 0 评论 -
Python 迭代模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 29 11:43:05 2018@author: mz"""class Iterator(object): def Next(self): pass def HasNext(self): pass def First(self): ...原创 2018-03-29 15:28:31 · 388 阅读 · 0 评论 -
Python 访问者模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 29 16:52:56 2018@author: mz"""class Aggregate(object): def __init__(self): self._elmlst = [] def Attach(self, elm): sel...原创 2018-03-29 19:25:27 · 205 阅读 · 0 评论 -
Python 备忘录模式
Created on Sun Mar 18 00:30:51 2018@author: mz"""class Original(object): def save(self, state): print("save status: %s" %(state)) self.__status = state def get(se...原创 2018-03-18 00:49:07 · 267 阅读 · 0 评论 -
yield
yield的优势是可以实时将递归的值反馈回来,形成生成器。上代码:# -*- coding: utf-8 -*-"""Created on Fri Feb 9 09:16:02 2018@author: mz"""class Sum(object): def add(self,a, b): return a +b; def foreach(...原创 2018-02-09 12:10:29 · 105 阅读 · 0 评论 -
Python 责任链模式实现
# -*- coding: utf-8 -*-"""Created on Mon Feb 26 11:45:46 2018@author: mz"""class Handler(object): def __init__(self): self.handler = None def Handle(self): pass ...原创 2018-02-26 14:15:52 · 234 阅读 · 0 评论 -
Python 状态模式
# -*- coding: utf-8 -*-"""Created on Mon Feb 26 20:45:13 2018@author: mz"""class Status(object): def Handle(self, rhs): pass class AStatus(Status): def Handle(self, rhs): ...原创 2018-02-26 21:38:55 · 152 阅读 · 0 评论 -
Python 策略模式
简单的用策略模式熟悉Python编程# -*- coding: utf-8 -*-"""Created on Mon Feb 12 15:48:29 2018@author: mz"""class Strategy(object): def action(self): pass class ConcreteStrategyA(Strategy...原创 2018-02-12 17:01:49 · 149 阅读 · 0 评论 -
Python 组合模式
# -*- coding: utf-8 -*-"""Created on Mon Feb 12 16:30:45 2018@author: mz"""class Component(object): def __init__(self, name): self.name = name self.child = [] ...原创 2018-02-12 17:28:52 · 286 阅读 · 0 评论 -
Python 装饰器模式
# -*- coding: utf-8 -*-"""Created on Sat Feb 24 11:37:17 2018@author: mz"""class Warrior: def __init__(self): self.attrack = 100 self.defend = 200 de...原创 2018-02-24 16:37:40 · 237 阅读 · 0 评论 -
Python 之工厂方法
# -*- coding: utf-8 -*-"""Created on Sat Mar 3 21:42:27 2018@author: mz"""class IFactory(object): def Product(self): pass class IMethod(object): def DoAsIMean(self): ...原创 2018-03-03 21:55:14 · 1355 阅读 · 0 评论 -
Python 中介模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 15 15:26:07 2018@author: mz"""class Mediator(object): def declare(self, msg, owner): self.__receiver.receive(msg) def ...原创 2018-03-18 00:04:16 · 289 阅读 · 0 评论 -
Python 桥接模式
# -*- coding: utf-8 -*-"""Created on Thu Mar 15 12:01:02 2018@author: mz"""class Phone(object): def setGame(self, rhs): self.game = rhs class IOSPhone(Phone): def playGa...原创 2018-03-18 00:05:57 · 151 阅读 · 0 评论 -
Python 抽象工厂
# -*- coding: utf-8 -*-"""Created on Sat Mar 3 21:56:58 2018@author: mz"""class IFactory(object): def ProduceB(self): pass def ProduceA(self): pass class...原创 2018-03-18 00:07:24 · 227 阅读 · 0 评论 -
Python 适配器模式
# -*- coding: utf-8 -*-"""Created on Sun Mar 18 00:08:14 2018@author: mz"""class Target(object): def charge(self, adaptor): print("110V charge on 220V->") adaptor...原创 2018-03-18 00:14:35 · 253 阅读 · 0 评论 -
KMeans算法实现
闲得,自己琢磨了KMeans算法,记录下。原理网络一大把,不再累述# -*- coding: utf-8 -*-"""Created on Wed May 16 23:02:51 2018@author: mz"""import mathimport randomfrom sklearn import datasetsimport numpy as npimport copy...原创 2018-05-31 23:55:08 · 360 阅读 · 0 评论