标签:dom return instance color tin pre exti int for
多例模式【Multition Pattern 】
public class Emperor { public String name = ""; private static int numOfEmperor = 2; private static ArrayList<Emperor> e = new ArrayList<Emperor>(); static { for (int i = 0; i < numOfEmperor; i++) { e.add(new Emperor("emperor"+i)); } } private Emperor(String name){ this.name = name; } public static Emperor getInstance(){ Random r = new Random(); return e.get(r.nextInt(numOfEmperor)); } }
一天一个设计模式,嘿嘿!
标签:dom return instance color tin pre exti int for
原文地址:http://www.cnblogs.com/mbky/p/6291077.html