昆仑万维做网站,宝塔面板一键部署wordpress打不开,杭州网站建设推荐q479185700上墙,源码网站违法吗单例模式工厂模式代理模式#xff08;proxy#xff09;
一、设计模式
设计模式是前辈们经过无数次实践所总结的一些方法#xff08;针对特定问题的特定方法#xff09;
这些设计模式中的方法都是经过反复使用过的。 二、常用的设计模式有哪些#xff1f;
1、单例模式proxy
一、设计模式
设计模式是前辈们经过无数次实践所总结的一些方法针对特定问题的特定方法
这些设计模式中的方法都是经过反复使用过的。 二、常用的设计模式有哪些
1、单例模式懒汉式、饿汉式
步骤 1、构造方法私有化让除了自己类能创建其他类都不能创建。
2、在自己的类中创建一个单实例懒汉模式是在需要的时候才创建饿汉模式是一开始就创建 3、提供一个方法获取该实例对象 饿汉式代码实例 ...
单例式
public class Singleton {private static Singleton singleton;private Singleton() {}public static Singleton getInstance() {if (singleton null) {singleton new Singleton();}return singleton;}
}
懒汉式
public class Singleton {private static Singleton instance;private Singleton (){}public static synchronized Singleton getInstance() {if (instance null) {instance new Singleton();}return instance;}
}
饿汉式
public class Singleton {private static Singleton instance new Singleton();private Singleton (){}public static Singleton getInstance() {return instance;}
} 2、工厂模式 spring IOC就是使用了工厂模式对象的创建都交给一个工厂去创建。
3、代理模式 spring AOP就是使用的动态代理模式。