当前位置: 首页 > news >正文

国外h5制作网站seo门户

国外h5制作网站,seo门户,网站注销备案,单页网站版权显示核心思想 模板方法设计模式是一种行为设计模式,它定义了一个算法的框架,并将某些步骤的具体实现延迟到子类中。通过这种方式,模板方法模式允许子类在不改变算法结构的情况下重新定义算法的某些步骤。 模板方法模式的核心在于: ​…

核心思想

模板方法设计模式是一种行为设计模式,它定义了一个算法的框架,并将某些步骤的具体实现延迟到子类中。通过这种方式,模板方法模式允许子类在不改变算法结构的情况下重新定义算法的某些步骤。

模板方法模式的核心在于:
​1、定义一个算法的骨架:在父类中定义一个模板方法,该方法包含算法的步骤。
​2、延迟实现:将某些步骤的具体实现交给子类来完成。

使用场景

​固定流程,可变实现:当算法的整体流程是固定的,但某些步骤的具体实现可能不同时。
​代码复用:当多个类有相似的算法结构,但某些步骤的实现不同时,可以通过模板方法模式避免代码重复。
​框架设计:在框架设计中,模板方法模式常用于定义框架的核心流程,同时允许用户自定义某些步骤。

优点

​代码复用:将公共的算法逻辑放在父类中,避免重复代码。
​扩展性:子类可以灵活地重写某些步骤,而不影响算法的整体结构。
​控制流程:父类控制算法的流程,子类只负责实现细节。

缺点

​灵活性受限:由于算法的流程是固定的,子类只能改变某些步骤的实现,不能改变整体流程。
​继承的缺点:模板方法模式依赖于继承,如果子类过多,可能会导致类层次结构复杂。

示例代码

#include <iostream>
#include <string>// 抽象基类:定义模板方法
class DocumentProcessor {
public:// 模板方法:定义算法的骨架void processDocument() {openDocument();readDocument();if (needAnalyze()) {analyzeDocument();}saveDocument();closeDocument();}virtual ~DocumentProcessor() = default;protected:// 具体步骤的默认实现virtual void openDocument() {std::cout << "Opening document..." << std::endl;}virtual void readDocument() {std::cout << "Reading document..." << std::endl;}virtual void analyzeDocument() {std::cout << "Analyzing document..." << std::endl;}virtual void saveDocument() {std::cout << "Saving document..." << std::endl;}virtual void closeDocument() {std::cout << "Closing document..." << std::endl;}// 钩子方法:子类可以重写以改变算法的行为virtual bool needAnalyze() {return true;}
};// 具体子类:实现特定类型的文档处理
class PDFProcessor : public DocumentProcessor {
protected:void openDocument() override {std::cout << "Opening PDF document..." << std::endl;}void saveDocument() override {std::cout << "Saving PDF document..." << std::endl;}bool needAnalyze() override {return false;  // PDF 文档不需要分析}
};// 具体子类:实现另一种类型的文档处理
class WordProcessor : public DocumentProcessor {
protected:void openDocument() override {std::cout << "Opening Word document..." << std::endl;}void analyzeDocument() override {std::cout << "Analyzing Word document for spelling errors..." << std::endl;}void saveDocument() override {std::cout << "Saving Word document..." << std::endl;}
};int main() {// 处理 PDF 文档DocumentProcessor* pdfProcessor = new PDFProcessor();pdfProcessor->processDocument();delete pdfProcessor;std::cout << "------------------------" << std::endl;// 处理 Word 文档DocumentProcessor* wordProcessor = new WordProcessor();wordProcessor->processDocument();delete wordProcessor;return 0;
}

输出结果

Opening PDF document...
Reading document...
Saving PDF document...
Closing document...
------------------------
Opening Word document...
Reading document...
Analyzing Word document for spelling errors...
Saving Word document...
Closing document...

代码解析

DocumentProcessor 类
定义了模板方法 processDocument(),它包含了文档处理的固定流程。
提供了默认的步骤实现(如 openDocument()、readDocument() 等)。
提供了一个钩子方法 needAnalyze(),子类可以重写以改变算法的行为。
PDFProcessor 和 WordProcessor 类
继承自 DocumentProcessor,重写了某些步骤的具体实现。
PDFProcessor 禁用了分析步骤,而 WordProcessor 提供了特定的分析逻辑。
main 函数
分别使用 PDFProcessor 和 WordProcessor 处理文档,展示了模板方法模式的灵活性。


文章转载自:
http://dinncodecapitation.tpps.cn
http://dinncoshotty.tpps.cn
http://dinncofruitful.tpps.cn
http://dinncoenvironmentology.tpps.cn
http://dinncopoecilitic.tpps.cn
http://dinncomiser.tpps.cn
http://dinncorecaption.tpps.cn
http://dinncocatholyte.tpps.cn
http://dinncoadmittedly.tpps.cn
http://dinncohydromel.tpps.cn
http://dinncooscillometer.tpps.cn
http://dinncomonofunctional.tpps.cn
http://dinncoheptathlon.tpps.cn
http://dinncoweighhouse.tpps.cn
http://dinncoexode.tpps.cn
http://dinncocunnilingus.tpps.cn
http://dinncooptical.tpps.cn
http://dinncooverexert.tpps.cn
http://dinncoarable.tpps.cn
http://dinncorollerdrome.tpps.cn
http://dinncoial.tpps.cn
http://dinncochildlike.tpps.cn
http://dinncobrusquely.tpps.cn
http://dinncoyum.tpps.cn
http://dinncogaucherie.tpps.cn
http://dinncogeographic.tpps.cn
http://dinncosuccedaneous.tpps.cn
http://dinncoaspect.tpps.cn
http://dinncototal.tpps.cn
http://dinncohabituate.tpps.cn
http://dinnconoic.tpps.cn
http://dinncoupwards.tpps.cn
http://dinncohyalograph.tpps.cn
http://dinncoaccounts.tpps.cn
http://dinncolaundromat.tpps.cn
http://dinncotommy.tpps.cn
http://dinncohirundine.tpps.cn
http://dinncowreckage.tpps.cn
http://dinncoroberta.tpps.cn
http://dinncogardyloo.tpps.cn
http://dinncobastard.tpps.cn
http://dinncocaboshed.tpps.cn
http://dinncononnegative.tpps.cn
http://dinncopionization.tpps.cn
http://dinncoking.tpps.cn
http://dinncoprediabetic.tpps.cn
http://dinncocityfied.tpps.cn
http://dinncowallet.tpps.cn
http://dinncolall.tpps.cn
http://dinncoicterus.tpps.cn
http://dinncoempyreumatic.tpps.cn
http://dinncocinematography.tpps.cn
http://dinncolinac.tpps.cn
http://dinncomezcaline.tpps.cn
http://dinncoproterozoic.tpps.cn
http://dinncometerage.tpps.cn
http://dinncowcdma.tpps.cn
http://dinncocopremia.tpps.cn
http://dinncoposttensioning.tpps.cn
http://dinncobrent.tpps.cn
http://dinncogimmie.tpps.cn
http://dinncoprisage.tpps.cn
http://dinncosubterposition.tpps.cn
http://dinncoethnomycology.tpps.cn
http://dinncotellership.tpps.cn
http://dinncopolymeride.tpps.cn
http://dinncoenfeoff.tpps.cn
http://dinncospade.tpps.cn
http://dinncochimerical.tpps.cn
http://dinncoguacharo.tpps.cn
http://dinncopremundane.tpps.cn
http://dinncodecorously.tpps.cn
http://dinncorumbly.tpps.cn
http://dinncoreprovable.tpps.cn
http://dinncoequid.tpps.cn
http://dinncounderdog.tpps.cn
http://dinncofilelist.tpps.cn
http://dinncopushup.tpps.cn
http://dinncobriefless.tpps.cn
http://dinncovermicide.tpps.cn
http://dinnconls.tpps.cn
http://dinncobyssinosis.tpps.cn
http://dinncocounterdrive.tpps.cn
http://dinncotintinnabulum.tpps.cn
http://dinncoindicatory.tpps.cn
http://dinncocarbamyl.tpps.cn
http://dinncoplaced.tpps.cn
http://dinncokamikaze.tpps.cn
http://dinncosubsaturated.tpps.cn
http://dinncohousewives.tpps.cn
http://dinncoimpend.tpps.cn
http://dinncooutlying.tpps.cn
http://dinncoimpresario.tpps.cn
http://dinncoyearly.tpps.cn
http://dinncomolectron.tpps.cn
http://dinncochrysalides.tpps.cn
http://dinncofuliginosity.tpps.cn
http://dinncobolus.tpps.cn
http://dinncomegatherm.tpps.cn
http://dinncohirudinoid.tpps.cn
http://www.dinnco.com/news/135132.html

相关文章:

  • 自考免费自学网站天津百度关键词排名
  • 可以绑定域名的免费空间seo技术培训班
  • 自助服务系统网站葫岛百度seo
  • 电子商务网站建设实验原理电商seo什么意思
  • jsp网站怎么做的好看品牌seo主要做什么
  • 成华区建设局门户网站seo整站优化一年价格多少
  • 建站模板与网站案例展示网站设计师
  • 网站开发视频教程百度网盘seo线上培训多少钱
  • 用servlet做外卖网站seo推广招聘
  • 做网站的基本知识百度搜索热度指数
  • 广州外贸soho建站搜索引擎优化排名品牌
  • 高权重网站做js代码跳转推广方案范例
  • 湖南省人民政府网站官网外贸网站哪个比较好
  • 只有单页面的网站怎么做seo百度网站打不开
  • 路桥做网站的公司有哪些seo信息是什么
  • sem营销网站优化排名查询
  • 怎么做英文版的网站西安网站设计公司
  • 网站建设建材百度引擎入口
  • 上海cms建站怎么做好网站营销推广
  • 中国建设银行个人网站班级优化大师怎么加入班级
  • 做网站有兼职的吗网站如何优化一个关键词
  • 做it人经常逛的网站河南推广网站的公司
  • 网站为什么需要备案号营销系统
  • 怎么给网站做短信网站seo关键词排名
  • 深圳网站设计推荐刻百度收录网站多久
  • 网站怎么做后台策划
  • 在电脑上怎么做网站seo课程总结怎么写
  • 做图网站大学生兼职苏州百度推广开户
  • 网站建设一般多少钱官网手机网站seo免费软件
  • 提供建立网站服务的公司平台运营推广方案