Java设计模式 – 四大类型

设计模式 -- 四大类型

设计模式(Design pattern)是重构解决方案

根据书Design Patterns -- Elements of Reusable Object-Oriented Software(中文译名:设计模式 -- 可复用的面向对象软件元素) 中和 J2EE 所提到的,总共有 23 +8 种设计模式

这些模式可以分为四大类:创建型模式(Creational Patterns)、结构型模式(Structural

Patterns)、行为型模式(Behavioral Patterns)、J2EE 设计模式

创建型模式

这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象

这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活

包括

  1. 工厂模式(FactoryPattern)
  2. 抽象工厂模式(AbstractFactoryPattern)
  3. 单例模式(SingletonPattern)
  4. 建造者模式(BuilderPattern
  5. 原型模式(PrototypePattern)

结构型模式

这些设计模式关注类和对象的组合

继承的概念被用来组合接口和定义组合对象获得新功能的方式

包括

  1. 适配器模式(AdapterPattern)
  2. 桥接模式(BridgePattern)
  3. 过滤器模式(Filter、CriteriaPattern)
  4. 组合模式(CompositePattern)
  5. 装饰器模式(DecoratorPattern)
  6. 外观模式(FacadePattern)
  7. 享元模式(FlyweightPattern)
  8. 代理模式(ProxyPattern)

行为型模式

这些设计模式特别关注对象之间的通信

包括

  1. 责任链模式(ChainofResponsibilityPattern)
  2. 命令模式(CommandPattern)
  3. 解释器模式(InterpreterPattern)
  4. 迭代器模式(IteratorPattern)
  5. 中介者模式(MediatorPattern)
  6. 备忘录模式(MementoPattern)
  7. 观察者模式(ObserverPattern)
  8. 状态模式(StatePattern)
  9. 空对象模式(NullObjectPattern)
  10. 策略模式(StrategyPattern)
  11. 模板模式(TemplatePattern)
  12. 访问者模式(VisitorPattern

J2EE模式

这些设计模式特别关注表示层

这些模式是由 Sun Java Center 鉴定的

包括:

  1. MVC模式(MVCPattern)
  2. 业务代表模式(BusinessDelegatePattern)
  3. 组合实体模式(CompositeEntityPattern)
  4. 数据访问对象模式(DataAccessObjectPattern)
  5. 前端控制器模式(FrontControllerPattern)
  6. 拦截过滤器模式(InterceptingFilterPattern)
  7. 服务定位器模式(ServiceLocatorPattern)
  8. 传输对象模式(TransferObjectPattern)

下面用一个图片来整体描述一下设计模式之间的关系:

相关推荐
特立独行的猫A4 小时前
别再用 nohup 了:让应用在后台常驻的正确姿势与 systemd 服务详解
java·后端·python
一起_java4 小时前
技术文章-基于Dify-Agent的智能问答系统设计与实现
java·spring boot·后端·agent·dify
是2的10次方啊4 小时前
设计模式与生活·总论:AI 能替你砌墙,替不了你打地基
设计模式
Flynn Liang5 小时前
I/O 密集型高并发实战:Java 服务 10 维优化,从线程打满到 10 万 QPS
java·spring boot·性能优化·高并发·系统设计·虚拟线程·io密集型
吃我一窝jio6 小时前
Python与Go线程模型深度对比
java·开发语言·python
这个昵称不容易7 小时前
SpringBoot 购物推荐网站的设计与实现:120 个 Java 文件、147 个接口、13 张表,附真实运行截图
java·springboot·毕设
文丑颜不良啊7 小时前
LeetCode3041~3060题目解析
java·leetcode
文丑颜不良啊8 小时前
LeetCode3101~3120题目解析
java·leetcode
Resean02238 小时前
SpringMVC 6+源码分析(十一)视图渲染与异步请求(收尾篇)
java·spring·springmvc
靠沿9 小时前
MySQL数据库进阶——存储过程和触发器
java·数据库·mysql