This commit is contained in:
周伟
2022-05-11 19:04:14 +08:00
parent 9440ac7291
commit d9c5ffd627
826 changed files with 0 additions and 481675 deletions

View File

@@ -25,13 +25,7 @@
<meta name="generator" content="Hexo 4.2.0">
</head>
<body>
<div class="book-container">
<div class="book-sidebar">
@@ -55,373 +49,190 @@
<li><a href="/" class="current-tab">首页</a></li>
</ul>
<ul class="uncollapsible">
<li><a href="../">上一级</a></li>
</ul>
<ul class="uncollapsible">
<li>
<a href="/专栏/白话设计模式 28 讲(完)/00 生活中的设计模式:启程之前,请不要错过我.md.html">00 生活中的设计模式:启程之前,请不要错过我.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/01 监听模式:坑爹的热水器.md.html">01 监听模式:坑爹的热水器.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/02 适配模式:身高不够鞋来凑.md.html">02 适配模式:身高不够鞋来凑.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/03 状态模式:人与水的三态.md.html">03 状态模式:人与水的三态.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/04 单例模式:你是我生命的唯一.md.html">04 单例模式:你是我生命的唯一.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/05 职责模式:我的假条去哪了.md.html">05 职责模式:我的假条去哪了.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/06 中介模式:找房子问中介.md.html">06 中介模式:找房子问中介.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/07 代理模式:帮我拿一下快递.md.html">07 代理模式:帮我拿一下快递.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/08 装饰模式:你想怎么穿就怎么穿.md.html">08 装饰模式:你想怎么穿就怎么穿.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/09 工厂模式:你要拿铁还是摩卡.md.html">09 工厂模式:你要拿铁还是摩卡.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/10 迭代模式:下一个就是你了.md.html">10 迭代模式:下一个就是你了.md.html</a>
</li>
<li>
<a class="current-tab" href="/专栏/白话设计模式 28 讲(完)/11 组合模式:自己组装电脑.md.html">11 组合模式:自己组装电脑.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/12 构建模式:想要车还是庄园.md.html">12 构建模式:想要车还是庄园.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/13 克隆模式:给你一个分身术.md.html">13 克隆模式:给你一个分身术.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/14 策略模式:怎么来不重要,人到就行.md.html">14 策略模式:怎么来不重要,人到就行.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/15 命令模式:大闸蟹,走起!.md.html">15 命令模式:大闸蟹,走起!.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/16 备忘模式:好记性不如烂笔头.md.html">16 备忘模式:好记性不如烂笔头.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/17 享元模式:颜料很贵必须充分利用.md.html">17 享元模式:颜料很贵必须充分利用.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/18 外观模式:学妹别慌,学长帮你.md.html">18 外观模式:学妹别慌,学长帮你.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/19 访问模式:一千个读者一千个哈姆雷特.md.html">19 访问模式:一千个读者一千个哈姆雷特.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/20 生活中的设计模式:与经典设计模式的不解渊源.md.html">20 生活中的设计模式:与经典设计模式的不解渊源.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/21 生活中的设计模式:那些未完待续的设计模式.md.html">21 生活中的设计模式:那些未完待续的设计模式.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/22 深入解读过滤器模式:制作一杯鲜纯细腻的豆浆.md.html">22 深入解读过滤器模式:制作一杯鲜纯细腻的豆浆.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/23 深入解读对象池技术:共享让生活更便捷.md.html">23 深入解读对象池技术:共享让生活更便捷.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/24 深入解读回调机制:把你技能亮出来.md.html">24 深入解读回调机制:把你技能亮出来.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/25 谈谈我对设计模式的理解.md.html">25 谈谈我对设计模式的理解.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/26 谈谈我对设计原则的思考.md.html">26 谈谈我对设计原则的思考.md.html</a>
</li>
<li>
<a href="/专栏/白话设计模式 28 讲(完)/27 谈谈我对项目重构的看法.md.html">27 谈谈我对项目重构的看法.md.html</a>
</li>
</ul>
</div>
</div>
<div class="sidebar-toggle" onclick="sidebar_toggle()" onmouseover="add_inner()" onmouseleave="remove_inner()">
<div class="sidebar-toggle-inner"></div>
</div>
<script>
function add_inner() {
@@ -431,9 +242,6 @@
inner.classList.add('show')
}
function remove_inner() {
let inner = document.querySelector('.sidebar-toggle-inner')
@@ -441,9 +249,6 @@
inner.classList.remove('show')
}
function sidebar_toggle() {
let sidebar_toggle = document.querySelector('.sidebar-toggle')
@@ -473,9 +278,6 @@
}
function open_sidebar() {
let sidebar = document.querySelector('.book-sidebar')
@@ -499,13 +301,7 @@ function hide_canvas() {
overlay.classList.remove('show')
}
</script>
<div class="off-canvas-content">
<div class="columns">
@@ -571,193 +367,106 @@ function hide_canvas() {
<pre><code class="language-python">class Component:
&quot;组件,所有子配件的基类&quot;
def __init__(self, name):
self._name = name
def showInfo(self, indent = &quot;&quot;):
pass
def isComposite(self):
return False
def startup(self, indent = &quot;&quot;):
print(indent + self._name + &quot; 准备开始工作...&quot;)
def shutdown(self, indent = &quot;&quot;):
print(indent + self._name + &quot; 即将结束工作...&quot;)
class CPU(Component):
&quot;中央处理器&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;CPU:&quot; + self._name + &quot;,可以进行高速计算。&quot;)
class MemoryCard(Component):
&quot;内存条&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;内存:&quot; + self._name + &quot;,可以缓存数据,读写速度快。&quot;)
class HardDisk(Component):
&quot;硬盘&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;硬盘:&quot; + self._name + &quot;,可以永久存储数据,容量大。&quot;)
class GraphicsCard(Component):
&quot;显卡&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;显卡:&quot; + self._name + &quot;,可以高速计算和处理图形图像。&quot;)
class Battery(Component):
&quot;电源&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;电源:&quot; + self._name + &quot;,可以持续给主板和外接配件供电。&quot;)
class Fan(Component):
&quot;风扇&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;风扇:&quot; + self._name + &quot;辅助CPU散热。&quot;)
class Displayer(Component):
&quot;显示器&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent, end=&quot;&quot;)
print(&quot;显示器:&quot; + self._name + &quot;,负责内容的显示。&quot;)
class Composite(Component):
&quot;配件组合器&quot;
def __init__(self, name):
super().__init__(name)
self._components = []
def showInfo(self, indent):
print(self._name + &quot;,由以下部件组成:&quot;)
@@ -767,27 +476,15 @@ class Composite(Component):
for element in self._components:
element.showInfo(indent)
def isComposite(self):
return True
def addComponent(self, component):
self._components.append(component)
def removeComponent(self, component):
self._components.remove(component)
def startup(self, indent):
super().startup(indent)
@@ -797,9 +494,6 @@ class Composite(Component):
for element in self._components:
element.startup(indent)
def shutdown(self, indent):
super().startup(indent)
@@ -809,69 +503,39 @@ class Composite(Component):
for element in self._components:
element.shutdown(indent)
class Mainboard(Composite):
&quot;主板&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent + &quot;主板:&quot;, end=&quot;&quot;)
super().showInfo(indent)
class ComputerCase(Composite):
&quot;机箱&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent + &quot;机箱:&quot;, end=&quot;&quot;)
super().showInfo(indent)
class Computer(Composite):
&quot;电脑&quot;
def __init__(self, name):
super().__init__(name)
def showInfo(self, indent):
print(indent + &quot;电脑:&quot;, end=&quot;&quot;)
super().showInfo(indent)
</code></pre>
<p>测试代码:</p>
@@ -895,9 +559,6 @@ class Computer(Composite):
mainBoard.addComponent(hardDisk)
mainBoard.addComponent(graphicsCard)
battery = Battery(&quot;Antec VP 450P&quot;)
fan = Fan(&quot;DEEPCOOL 120T&quot;)
@@ -909,21 +570,12 @@ class Computer(Composite):
computerCase.addComponent(mainBoard)
computerCase.addComponent(fan)
displayer = Displayer(&quot;AOC LV243XIP&quot;)
computer = Computer(&quot;Tony DIY电脑&quot;)
computer.addComponent(displayer)
computer.addComponent(computerCase)
computer.showInfo(&quot;&quot;)
print(&quot;\n开机过程:&quot;)
@@ -933,9 +585,6 @@ class Computer(Composite):
print(&quot;\n关机过程:&quot;)
computer.shutdown(&quot;&quot;)
</code></pre>
<p>输出结果:</p>
@@ -959,9 +608,6 @@ class Computer(Composite):
显卡:Colorful iGame750,可以高速计算和处理图形图像。
风扇:DEEPCOOL 120T辅助CPU散热。
开机过程:
Tony DIY电脑 准备开始工作...
@@ -983,9 +629,6 @@ Tony DIY电脑 准备开始工作...
Colorful iGame750 准备开始工作...
DEEPCOOL 120T 准备开始工作...
关机过程:
Tony DIY电脑 准备开始工作...
@@ -1007,9 +650,6 @@ Tony DIY电脑 准备开始工作...
Colorful iGame750 即将结束工作...
DEEPCOOL 120T 即将结束工作...
</code></pre>
<h3>从剧情中思考组合模式</h3>
@@ -1087,9 +727,6 @@ Tony DIY电脑 准备开始工作...
</div>
</div>
</div>
</div>
@@ -1097,9 +734,6 @@ Tony DIY电脑 准备开始工作...
</div>
</div>
<a class="off-canvas-overlay" onclick="hide_canvas()"></a>
</div>
@@ -1115,17 +749,11 @@ Tony DIY电脑 准备开始工作...
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-NPSEEVD756');
@@ -1151,9 +779,6 @@ Tony DIY电脑 准备开始工作...
setCookie("lastPath", path)
}
function setCookie(cname, cvalue) {
var d = new Date();
@@ -1165,9 +790,6 @@ Tony DIY电脑 准备开始工作...
document.cookie = cname + "=" + cvalue + "; " + expires + ";path = /";
}
function getCookie(cname) {
var name = cname + "=";
@@ -1185,12 +807,6 @@ Tony DIY电脑 准备开始工作...
return "";
}
</script>
</html>