package com.test.design.multition;
import java.util.ArrayList;
import java.util.Random;
public class Multition {
private static int maxNum = 2; // 多例模式中的上限
private static ArrayList<Multition> multitions = new ArrayList<Multition>(maxNum);
static {
for (int i = 0; i < maxNum; i++) {
multitions.add(new Multition());
}
}
private Multition() {
}
public static Multition getInMultition() {
int index = new Random().nextInt(maxNum);
return multitions.get(index);
}
public static Multition getInMultition(int index) {
return multitions.get(index);
}
}
多例模式
最新推荐文章于 2023-12-28 23:57:23 发布