-- 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