我现在在用Java编写一个工作簿,如何在类里面设置用户的数据对管理员可见,而对其他用户不可见?用户可以看自己的数据

解决方案 »

  1.   

    加个if else 结构
    如果是管理员就显示一些他那看的,否则跳去else结构显示不能看的
      

  2.   

    哈哈 有点意思 
    管理员是用户的个内部类 数据是private 的
    这样貌似可行
    但是逻辑上有点别扭
      

  3.   

    我觉得用IF else的话会累死人,而且从面向对象的角度出发不知道有没有什么好的解决方法了,先MARK一下先!!
      

  4.   

    用OO的思想封装dataclass dataDemo {
    private int prority = 0; // From 1 to 5, for example
    private Object data = null; public dataDemo(Object obj, int prority) {
    this.data = obj;
    this.prority = prority;
    } public Object getData(int prority) throws Exception {
    if (prority < this.prority) {
    throw new Exception();
    }
    else return data;
    }

    public void resetData(Object obj, int prority) throws Exception {
    if (prority < this.prority) {
    throw new Exception();
    }
    else this.data = obj;
    }
    }