比如:有类A,B,C,他们的实例为a,b,c
那么如何在b,c,中访问a中的数据(不采用全局对象)
最好能给出示例代码,谢谢

解决方案 »

  1.   

    给b,c一个函数参数类型A或者想访问的a的数据的类型,传递a或想访问的a的数据进去就是了
      

  2.   

    谢谢楼上的,看来是我没有把问题阐述明白
    我的问题是这样的
    Class A
    {
         public int x;
         public A()
         {
         }
    }
    Class B
    {
         public B()
         {
             Thread th = new Thread();
             th.run();
         }
         
    }
    Class C
    {
         public C()
         {
             Thread th = new Thread();
             th.run();
         }
    }
    Class D
    {
         void main()
         {
              A a= new A();
              B b= new B();
              C c= new C();
         }
    }
    这里对象b和c分别包含了一个线程,我希望能在b和c的线程中访问a.x
    而且不能使用static把a或x定义成静态的,也不能用singleton模式来设计类A那么我该如何实现,请教高手,最好能给出代码
      

  3.   

    Class B
    {
    private A pA;
    public B( A a)
    {
    pA = a;//Use constructor
    Thread th = new Thread();
    th.run();
    }}