JDK和Spring中的设计模式

JDK中的设计模式(17)

创建型

1)工厂方法

Collection.iterator() 由具体的聚集类来确定使用哪一个Iterator

2)单例模式

Runtime.getRuntime()

3)建造者模式

StringBuilder

4)原型模式

Java中的Cloneable

结构性

1)适配器模式

InputStreamReader

OutputStreamWriter

RunnableAdapter

2)装饰器模式

io包 FileInputStream BufferedInputStream

3)代理模式

动态代理;RMI

4)外观模式

java.util.logging

5)桥接模式

JDBC

6)组合模式

dom

7)享元模式

Integer.valueOf

行为型

1)策略模式

线程池的四种拒绝策略

2)模板方法模式

AbstractList、AbstractMap等

InputStream、OutputStream

AQS

3)观察者模式

Swing中的Listener

4)迭代器模式

集合类中的iterator

5)责任链模式

J2EE中的Filter

6)命令模式

Runnable、Callable,ThreadPoolExecutor

7)备忘录模式

8)状态模式

9)访问者模式

10)中介者模式

11)解释器模式

 

Spring中的设计模式(6)

1)抽象工厂模式:

BeanFactory

2)代理模式:

AOP

3)模板方法模式:

AbstractApplicationContext中定义了一系列的抽象方法,比如refreshBeanFactory、closeBeanFactory、getBeanFactory。

4)单例模式:

Spring可以管理单例对象,控制对象为单例

5)原型模式:

Spring可以管理多例对象,控制对象为prototype

6)适配器模式:

Advice与Interceptor的适配

Adapter类接口Target

public interface AdvisorAdapter {
boolean supportsAdvice(Advice advice);
      MethodInterceptor getInterceptor(Advisor advisor);
} 

MethodBeforeAdviceAdapterAdapter

class MethodBeforeAdviceAdapter implements AdvisorAdapter, Serializable {
      public boolean supportsAdvice(Advice advice) {
            return (advice instanceof MethodBeforeAdvice);
      }
      public MethodInterceptor getInterceptor(Advisor advisor) {
            MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
      return new MethodBeforeAdviceInterceptor(advice);
      }
}

慢慢填坑

发布了423 篇原创文章 · 获赞 5858 · 访问量 91万+

猜你喜欢

转载自blog.csdn.net/hebtu666/article/details/103984816