zoukankan      html  css  js  c++  java
  • 设计模式-模板方法设计模式--Template Method design pattern

    /**
     * Abstract implementation of the {@link org.springframework.context.ApplicationContext}
     * interface. Doesn't mandate the type of storage used for configuration; simply
     * implements common context functionality. Uses the Template Method design pattern,
     * requiring concrete subclasses to implement abstract methods.
     *
     * <p>In contrast to a plain BeanFactory, an ApplicationContext is supposed
     * to detect special beans defined in its internal bean factory:
     * Therefore, this class automatically registers
     * {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessors},
     * {@link org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessors}
     * and {@link org.springframework.context.ApplicationListener ApplicationListeners}
     * which are defined as beans in the context.
     *
     * <p>A {@link org.springframework.context.MessageSource} may also be supplied
     * as a bean in the context, with the name "messageSource"; otherwise, message
     * resolution is delegated to the parent context. Furthermore, a multicaster
     * for application events can be supplied as "applicationEventMulticaster" bean
     * of type {@link org.springframework.context.event.ApplicationEventMulticaster}
     * in the context; otherwise, a default multicaster of type
     * {@link org.springframework.context.event.SimpleApplicationEventMulticaster} will be used.
     *
     * <p>Implements resource loading through extending
     * {@link org.springframework.core.io.DefaultResourceLoader}.
     * Consequently treats non-URL resource paths as class path resources
     * (supporting full class path resource names that include the package path,
     * e.g. "mypackage/myresource.dat"), unless the {@link #getResourceByPath}
     * method is overwritten in a subclass.
    

     

    今天看spring的代码,AbstractApplicationContext中的注释有提到Template Method design pattern ,就查了一下这种设计模式。

    参考:https://blog.csdn.net/qq_24692041/article/details/60961880

    这种设计模式,就是在父类中定义处理流程的框架,在子类中实现具体的处理方式。我的理解是,父类处理步骤,子类处理数据。其中父类的方法基于里氏转换原则,要final掉。

  • 相关阅读:
    洛谷 P1464 Function【动态规划(递推)/记忆化搜索(递归)】
    洛谷 P1426 小鱼会有危险吗【模拟/题意理解】
    洛谷 P2089 烤鸡【DFS递归/10重枚举】
    洛谷 P1579 哥德巴赫猜想(升级版)【筛素数/技巧性枚举/易错】
    洛谷 P1618 三连击(升级版)【DFS/next_permutation()/技巧性枚举/sprintf】
    sprintf 心得
    洛谷 P1478 陶陶摘苹果(升级版)【贪心/结构体排序/可用01背包待补】
    吉首大学 问题 L: 小李子的老年生活
    AtCoder Beginner Contest 084 D
    一维差值维护心得
  • 原文地址:https://www.cnblogs.com/zhizhiyin/p/11051738.html
Copyright © 2011-2022 走看看