设计模式
CodingBugs
Nothing is impossible.
展开
-
设计模式-适配器模式
源码:https://github.com/blogshixiaodong/design-patterns.git /* * 原始对象 * */ public class Banner { private String string; public Banner(String string) { this.string = string; } ...原创 2018-04-08 23:05:55 · 101 阅读 · 0 评论 -
设计模式-模板方法模式
//AbstractDisplay.java public abstract class AbstractDisplay { //抽象的方法具体细节由子类来实现 public abstract void open(); public abstract void print(); public abstract void close(); //fina...原创 2018-04-10 23:19:29 · 112 阅读 · 0 评论 -
设计模式-工厂方法模式
产品类: public abstract class Product { public abstract void use(); } public class IDCard extends Product { private String owner; IDCard(String owner) { System.out.println("mak...原创 2018-04-10 23:44:47 · 110 阅读 · 0 评论 -
设计模式-单例模式
/* * 饿汉式 * 避免多线程的问题,在类被装载时就实例化对象 * */ public class Singleton { private static Singleton singleton = new Singleton(); private Singleton() { System.out.println("无法直接new对象"); } ...原创 2018-04-03 23:10:39 · 83 阅读 · 0 评论 -
设计模式-原型模式
/* * 只有实现标记接口Cloneable才能clone,此时的clone是浅复制,深复制需要重载clone方法 * 且Object是没有实现Cloneable接口的 * */ public interface Product extends Cloneable { public abstract void use(String s); public abstract Pro...原创 2018-04-12 00:22:23 · 113 阅读 · 0 评论 -
设计模式-迭代器模式
/* * 需要遍历的集合的接口,实现该接口的类将成为一个可以保存多个元素的集合 * */ public interface Aggregate { //遍历集合的迭代器 public abstract Iterator iteraor(); } public class BookShelf implements Aggregate { private Book[] boo...原创 2018-04-05 17:48:21 · 89 阅读 · 0 评论