开闭原则
主要在4个方面体现
- 使用final关键字来限定核心组件中的核心方法
- 大量地在核心组件中使用private方法,子类不允许通过继承的方式改变父类的默认行为
- 限定某些类对外部程序不可见,不允许外部程序对这些系统配置类进行访问,从而杜绝外部程序对SpringMVC默认行为的任何修改
- 提供自定义扩展接口(扩展切入点),却不提供完整覆盖默认行为的方式
SpringMVC的这一条设计原则说的是:不能动其根本,只能在一定范围内进行扩展
行散神不散
- 行——SpringMVC拥有多种不同的行为模式
- 神——SpringMVC总是沿着一条固定的逻辑主线运行
也就是说:SpringMVC的逻辑主线始终不变,而行为模式却可以多种多样
简化
可以从2个方面看出来:
- 注解——简化各类配置定义
①简化请求映射的定义
②消除Controller对接口的依赖,之前控制器需要实现Controller接口,即依赖Controller接口,Controller会限制你的处理模式。
③成为框架进行逻辑处理的标识,如@RequestBody既是对Controller的一种逻辑声明,也成为了框架本身对相关元素进行处理的一个标识符 - Schema Based XML——简化组件定义
Schema Based XML用于进行XML配置的简化,只要在XML文件的开头加入相关的定义
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
</beans>