We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f2d5bf3 commit c7d1a14Copy full SHA for c7d1a14
创建型模式-享元模式.py
@@ -19,6 +19,9 @@ def __new__(cls, identity):
19
假设相同的学号只会有1个学生
20
:param identity:
21
:return:
22
+
23
+ 这个是享元模式,有人一看到重新 __new__就神经过敏,但凡是重写了__new__的代码他都认为是单例模式。主要是没有掌握类的一些概念的本质,死记硬背形式造成的错误认知。
24
+ 最起码要知道__new__是干啥,__init__是干啥,不知道的话救护死记硬背单例模式的形式。
25
"""
26
obj = cls.pool.get(identity, None)
27
if not obj:
0 commit comments