DesignPatterns
Heavy_Dream
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
The Singleton pattern
作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。这个类称为单例类。单例模式的结构 单例模式的特点:单例类只能有一个实例。单例类必须自己创建自己的唯一实例。单例类必须给所有其他对象提供这一实例。 饿汉式单例类public class EagerSingleton { private stat翻译 2016-11-30 22:57:34 · 422 阅读 · 0 评论 -
The Factory pattern
public class Factory {public static void main(String[] args) {//ClientIFruit fruit=Factorytemp.getFruit("香蕉");//这里为什么要使用接口的类型,因为接口的引用可以接收实现此接口的类的实例if(fruit!= null){System.out.println(fruit.g翻译 2016-11-30 22:58:11 · 386 阅读 · 0 评论 -
The Template method pattern
public class TemplateMethodDemo {public static void main(String[] args) {Teacher test=new Javatreacher("张三");//动态绑定test.work();Teacher test1=new Datatreacher("李四");test1.work();}}翻译 2016-11-30 22:58:59 · 363 阅读 · 0 评论 -
The Strategy pattern
public class Strategy {public static void main(String[] args) {int [] array=new int[]{26,25,15,42,36,16,12};IInfo test1=new BubbleSort(); //接口引用指向实现了此接口的类创建的实例,创建具体的策略对象IInfo test2=new SelectS翻译 2016-11-30 23:00:01 · 413 阅读 · 0 评论
分享