博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
原型模式ProtoType
阅读量:4614 次
发布时间:2019-06-09

本文共 715 字,大约阅读时间需要 2 分钟。

#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time    : 2019/3/4 21:49# @Author  : ChenAdong# @email   : aiswell@foxmail.comimport copyclass ProtoType:	def __init__(self):		self._object = {}	def register_object(self, name, obj):		self._object[name] = obj	def unregister_object(self, name):		del self._object[name]	def clone(self, name, **attr):		_obj = copy.deepcopy(self._object.get(name))		print(_obj)		_obj.__dict__.update(attr)		return _objif __name__ == "__main__":	class Test:		pass	t = Test()	prototype = ProtoType()	prototype.register_object("c", t)	t1 = prototype.clone("c", attr_1=1)	print(t1.attr_1)

<__main__.Test object at 0x000002340CDF2630>

1

 

  

转载于:https://www.cnblogs.com/chenadong/p/10473595.html

你可能感兴趣的文章
数据结构(五)之直接插入排序
查看>>
SQL函数——LENGTH()和LENGTHB()
查看>>
vim - manual -个人笔记
查看>>
为什么我们程序员难晋升
查看>>
详解Javascript中prototype属性(推荐)
查看>>
angularjs实现首页轮播图
查看>>
Git 对象 和checkout 和stash的笔记
查看>>
团队项目总结2-服务器通信模型和顺序图
查看>>
hdu 1085 Holding Bin-Laden Captive!
查看>>
[周记]8.7~8.16
查看>>
递归定义
查看>>
kindeditor 代码高亮设置
查看>>
互联网产品的商业模式
查看>>
图的邻接表存储
查看>>
2018 leetcode
查看>>
各浏览器对 onbeforeunload 事件的支持与触发条件实现有差异
查看>>
PHP中获取当前页面的完整URL
查看>>
所谓输入掩码技术,即只有数字键起作用
查看>>
Display对象,Displayable对象
查看>>
安装oracle11G,10G时都会出现:注册ocx时出现OLE初始化错误或ocx装载错误对话框
查看>>