mirror of
https://github.com/zhwei820/learn.lianglianglee.com.git
synced 2025-11-17 06:33:49 +08:00
fix img
This commit is contained in:
@@ -369,7 +369,7 @@ tony == karry: True
|
||||
<p>装饰器的实质就是对传进来的参数进行补充,可以在原有的类不做任何代码变动的前提下增加额外的功能,使用装饰器可以装饰多个类。用装饰器的方式来实现单例模式,通用性非常好,在实际项目中用的非常多。</p>
|
||||
<h4>类图</h4>
|
||||
<p>上面的代码框架可用类图表示如下:</p>
|
||||
<p><img src="assets/55e4e340-c394-11e8-b5ca-0da8fdb41124.jpg" alt="enter image description here" /></p>
|
||||
<p><img src="assets/55e4e340-c394-11e8-b5ca-0da8fdb41124.jpg" alt="png" /></p>
|
||||
<h4>基于框架的实现</h4>
|
||||
<p>通过上面的方式三,我们知道,定义通用的装饰器方法之后再用它去修饰一个类,这个类就成了一个单例类,使用起来非常方便。最开始的示例代码我们假设它为 version 1.0,那么再看看基于装饰器的 version 2.0 吧。</p>
|
||||
<pre><code class="language-python">@singletonDecorator
|
||||
|
||||
Reference in New Issue
Block a user