-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
615 lines (240 loc) · 18.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<!doctype html>
<html class="theme-next mist use-motion">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />
<meta name="keywords" content="Hexo, NexT" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />
<meta property="og:type" content="website">
<meta property="og:title" content="bugMaker">
<meta property="og:url" content="http://jinshaoyong.site/index.html">
<meta property="og:site_name" content="bugMaker">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="bugMaker">
<script type="text/javascript" id="hexo.configuration">
var NexT = window.NexT || {};
var CONFIG = {
scheme: 'Mist',
sidebar: {"position":"left","display":"post"},
fancybox: true,
motion: true,
duoshuo: {
userId: '0',
author: '博主'
}
};
</script>
<link rel="canonical" href="http://jinshaoyong.site/"/>
<title> bugMaker </title>
</head>
<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left
page-home
">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
<div class="header-inner"><div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">bugMaker</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle"></p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
首页
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives" rel="section">
归档
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags" rel="section">
标签
</a>
</li>
<li class="menu-item menu-item-schedule">
<a href="/schedule" rel="section">
日程
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal " itemscope itemtype="//schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/12/30/设计模式之模版方法/" itemprop="url">
未命名
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-12-30T01:36:06+08:00" content="2016-12-30">
2016-12-30
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<hr>
<p>title: 设计模式之模版方法<br>date: 2016-12-30 01:36:06</p>
<h2 id="tags"><a href="#tags" class="headerlink" title="tags:"></a>tags:</h2><h5 id="定义:"><a href="#定义:" class="headerlink" title="定义:"></a>定义:</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div></pre></td><td class="code"><pre><div class="line">模板方法模式:在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中。 </div><div class="line">模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤。</div><div class="line">~~~ </div><div class="line"></div><div class="line">##### demo: </div><div class="line">在很多订单系统中,订单操作的流程大致步骤都是相同的。 </div><div class="line"> 1. 构建上下文 </div><div class="line"> 2. 校验 </div><div class="line"> 3. 创建订单 </div><div class="line"> 4. 入库 </div><div class="line"> 但是一些具体的逻辑和需求是不一定的。比如创建订单和修改项目。 </div><div class="line"> </div><div class="line">``` java</div><div class="line">抽象类:AbstractOrderOperationTemplate</div><div class="line"></div><div class="line">public abstract class AbstractOrderOperationTemplate<Context extends OrderContext>{</div><div class="line"> protected ApplicationContext applicationContext;</div><div class="line"> //校验</div><div class="line"> protected List<OrderValidator> orderValidators;</div><div class="line"></div><div class="line"> /**</div><div class="line"> * 操作流程</div><div class="line"> */</div><div class="line"> public final void operate(Context context) throws OrderException {</div><div class="line"> buildContext(context); //构建</div><div class="line"> validate(context); //校验</div><div class="line"> process(context); //下单</div><div class="line"> store(context); //入库</div><div class="line"> }</div><div class="line"> </div><div class="line"> //构建上下文</div><div class="line"> protected abstract void buildContext(Context context);</div><div class="line"> //校验逻辑</div><div class="line"> protected void validate(Context context) throws OrderException {</div><div class="line"> if (CollectionUtils.isNotEmpty(orderValidators)) {</div><div class="line"> for (OrderValidator validator : orderValidators) {</div><div class="line"> validator.validate(context);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> //下单流程</div><div class="line"> protected abstract void process(Context context) throws OrderException;</div><div class="line"> //入库</div><div class="line"> protected abstract void store(Context context);</div><div class="line"> </div><div class="line">下单:OrderCreateTemplate</div><div class="line">public class OrderCreateTemplate extends AbstractOrderOperationTemplate<OrderCreateContext> {</div><div class="line"></div><div class="line"> @Override</div><div class="line"> protected void buildContext(OrderCreateContext context) {</div><div class="line"> </div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> @Override</div><div class="line"> protected void process(OrderCreateContext context) {</div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> @Override</div><div class="line"> protected void store(OrderCreateContext context) {</div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> }</div><div class="line"> </div><div class="line">修改订单:OrderChangeTemplate</div><div class="line"></div><div class="line">public class OrderChangeTemplate</div><div class="line"> extends AbstractOrderOperationTemplate<OrderChangeExamItemContext> {</div><div class="line"> </div><div class="line"> @Override</div><div class="line"> protected void buildContext(OrderCreateContext context) {</div><div class="line"> </div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> @Override</div><div class="line"> protected void process(OrderCreateContext context) {</div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> @Override</div><div class="line"> protected void store(OrderCreateContext context) {</div><div class="line"> //code list do something</div><div class="line"> }</div><div class="line"> </div><div class="line"> }</div><div class="line"></div><div class="line">``` </div><div class="line">上面将创建订单和修改订单的整体流程定义在抽象类AbstractOrderOperationTemplate中,其中operate方法为final,然后validate方法提供了默认实,而其他三个方法均为abstract,需要在ordercreate和orderchange类中自己实现。 </div><div class="line"></div><div class="line">##### 总结</div></pre></td></tr></table></figure>
<ol>
<li>“模版方法”定义了算法的步骤。 </li>
<li>模版方法是一种代码复用的重要技巧。</li>
<li>模版方法可以定义具体,抽象方法。其中抽象方法由子类实现。</li>
<li>最好将算法骨架方法改为final。<br>~~~<br>//todo 模版方法的钩子以及与策略模式的比较,特殊的工厂方法。</li>
</ol>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="//schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/12/12/index/" itemprop="url">
Hello World
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-12-12T20:57:14+08:00" content="2016-12-12">
2016-12-12
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h3 id="准备开始写博客了,希望这个地方不是我放垃圾的地方"><a href="#准备开始写博客了,希望这个地方不是我放垃圾的地方" class="headerlink" title="准备开始写博客了,希望这个地方不是我放垃圾的地方"></a>准备开始写博客了,希望这个地方不是我放垃圾的地方</h3><p><strong> Improve myself to change the world </strong> </p>
<h5 id="在这里我会写包含但不仅仅以下内容"><a href="#在这里我会写包含但不仅仅以下内容" class="headerlink" title="在这里我会写包含但不仅仅以下内容"></a>在这里我会写包含但不仅仅以下内容</h5><ul>
<li><font color="#0099ff" size="5">学习与实践 </font> </li>
<li><font color="#0099ff" size="5">牢骚 </font></li>
<li><font color="#0099ff" size="5">感悟</font>
</li>
</ul>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
</section>
</div>
</div>
<div class="sidebar-toggle">
<div class="sidebar-toggle-line-wrap">
<span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
<span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
<span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
</div>
</div>
<aside id="sidebar" class="sidebar">
<div class="sidebar-inner">
<section class="site-overview sidebar-panel sidebar-panel-active ">
<div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
<img class="site-author-image" itemprop="image"
src="/images/avatar.gif"
alt="king" />
<p class="site-author-name" itemprop="name">king</p>
<p class="site-description motion-element" itemprop="description"></p>
</div>
<nav class="site-state motion-element">
<div class="site-state-item site-state-posts">
<a href="/archives">
<span class="site-state-item-count">2</span>
<span class="site-state-item-name">日志</span>
</a>
</div>
</nav>
<div class="links-of-author motion-element">
</div>
</section>
</div>
</aside>
</div>
</main>
<footer id="footer" class="footer">
<div class="footer-inner">
<div class="copyright" >
©
<span itemprop="copyrightYear">2016</span>
<span class="with-love">
<i class="fa fa-heart"></i>
</span>
<span class="author" itemprop="copyrightHolder">king</span>
</div>
<div class="powered-by">
由 <a class="theme-link" href="http://jinshaoyong.site">金少勇</a> 强力驱动
</div>
<div class="theme-info">
主题 -
<a class="theme-link" href="https://github.com/collery">
爱你
</a>
</div>
</div>
</footer>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
</div>
</div>
<script type="text/javascript">
if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
window.Promise = null;
}
</script>
<script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
<script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
<script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>
</body>
</html>