惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
B
Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
P
Privacy International News Feed
L
LINUX DO - 最新话题
博客园_首页
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
C
Cisco Blogs
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
罗磊的独立博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
A
About on SuperTechFans
G
GRAHAM CLULEY
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
D
DataBreaches.Net
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
I
InfoQ
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 叶小钗
Project Zero
Project Zero

博客园 - 蓝风笨笨

简化问题的模式 为什么要优先使用组合而不是继承 SequenceFile介绍 基于Hadoop Sequencefile的小文件解决方案 Hadoop命令解释 Hadoop源代码分析之Configuration - 蓝风笨笨 onSaveInstanceState和onRestoreInstanceState触发的时机 Android 获取AndroidManifest.xml文件versionCode,versionName属性 . 术语解释 Android开发指南中文版(十四)User Interface-Binding to Data with AdapterView Windows环境下Android Sdk源码下载 Android开发指南中文版(十三)User Interface-Notifications Android开发指南中文版(十二)User Interface-Dialogs Serializable 和 Parcelable 区别 Android开发指南中文版(十一)User Interface-Menus Hierarchy Viewer Tool Android开发指南中文版(十)User Interface-Input Events Android开发指南中文版(九)User Interface-XML Layouts Android开发指南中文版(八)User Interface
模板模式和策略模式
蓝风笨笨 · 2013-07-11 · via 博客园 - 蓝风笨笨

模板模式和策略模式的应用情景类似,但实现方式不同,前者使用继承,后者使用委托。

  模板模式有可能是最“古老”的模式之一,在使用面向对象技术的早期,“继承”大行其道,很多设计人员可能不自觉地使用过模板模式。模板模式的缺点是把具体实现和通用算法紧密地耦合起来,使得具体实现只能被一个通用算法操纵。然而在继承关系中,父类的信息可以更多地暴露给子类,这种(违背面向对象设计原则的)微妙的沟通在一些特定应用中显得更加灵活和方便。

  策略模式是委托的经典用法。策略模式消除了通用算法和具体实现的耦合,使得具体实现可以被多个通用算法操纵。策略模式也增加了类层次,比模板模式复杂。

  模板模式和策略模式通常可以互相替换。它们都像试卷,模板模式是填空题,策略模式是选择题。

模板模式

策略模式