首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Java设计形式之模板方法模式

2012-09-07 
Java设计模式之模板方法模式TEMPLATE METHOD (Class Behavioral)?Purpose?Identifies the framework of an

Java设计模式之模板方法模式

TEMPLATE METHOD (Class Behavioral)?
Purpose?
Identifies the framework of an algorithm, allowing implementing?
classes to define the actual behavior.?
Use When?
1 A single abstract implementation of an algorithm is needed.?
2 Common behavior among subclasses should be localized to a?
? common class.?
3 Parent classes should be able to uniformly invoke behavior in?
?? their subclasses.?
4 Most or all subclasses need to implement the behavior.?
Example?
A parent class, InstantMessage, will likely have all the methods?
required to handle sending a message. However, the actual?
serialization of the data to send may vary depending on the?
implementation. A video message and a plain text message?
will require different algorithms in order to serialize the data?
correctly. Subclasses of InstantMessage can provide their?
own implementation of the serialization method, allowing the?
parent class to work with them without understanding their?
implementation details.?
new?ConcreteClassB();??

  • ????????ac.templateMethod();??
  • ????}??
  • } ?

  • 热点排行