我有一个类嵌套是这样的:CSurfaceView - CRectangle - CMesh - CContentReader
即CRectangle要在CSurfaceView上用到,CRecangle包含到CMesh,而CMesh包含CContentReader其中,CContentReader要用到Context(在Activity中就是this值)读取文件。
这个就要麻烦很多了,Context要经过这么多层传到CContentReader中,
请问,Context要保存到类中,是不是在类中声明Context并在构造函数中赋值就可以了?

解决方案 »

  1.   

    你的想法是对的:
    public class CContentReader extends CMesh { private Context context; public CContentReader(Context context){
    this.context=context;
    }}
      

  2.   

    CSurfaceView - CRectangle - CMesh - CContentReader
    其他类需要Context么?
    如果需要统一设置一个Context的构造函数
    如果不需要,也可以给CContentReader设置一个Set访问器
      

  3.   

    额额,谢谢各位前辈
    只是CContentReader需要,但它被嵌套到最底层了,
    这样其它不需要的上层都要参与了传递,很麻烦的样子。要怎么设置set访问器哪,才能方便些,谢谢