Differences between revisions 2 and 3
Revision 2 as of 2006-06-16 09:19:59
Size: 808
Editor: HoLin
Comment:
Revision 3 as of 2009-12-25 07:14:52
Size: 809
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
-- flyaflya [[[DateTime(2005-08-04T09:26:24Z)]]]
[[TableOfContents]]
-- flyaflya [<<DateTime(2005-08-04T09:26:24Z)>>]
<<TableOfContents>>
Line 46: Line 46:
 * 看例子感觉和接口很像 --[:holin: HoLin]  * 看例子感觉和接口很像 --[[holin| HoLin]]

-- flyaflya [2005-08-04 09:26:24]

1. Template Method(模板方法)

1.1. 意图

定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。

1.2. 代码

   1 class Base:
   2     def doAll(self):
   3         self.doThis()
   4         self.doThat()
   5     
   6 class Foo(Base):
   7     def doThis(self):
   8         print "do this"
   9     def doThat(self):
  10         print "do that"
  11 
  12 #测试
  13 Foo a
  14 a.doAll()
  15 #输出
  16 #do this
  17 #do that

1.3. 例子

声明

   1 

使用情景

   1 

1.4. 特殊说明

1.5. 反馈

  • 看例子感觉和接口很像 --HoLin

TemplateMethodPattern (last edited 2009-12-25 07:14:52 by localhost)