依赖引用关系说明
位于上层的component是看不到下层的,而下层则可以使用上层的,但不能引用同一层相邻component内的实例。
依赖图例子
@Subcomponent 子组件绑定 绑定子组件中的对象除了可以依赖自身模块中绑定的对象外,
- 还可以依赖于其父组件或任何祖先组件中绑定的任何对象。
- 另一方面,绑定在父组件中的对象不能依赖于绑定在子组件中的对象。 绑定在一个子组件中的对象也不能依赖于同级子组件中绑定的对象。
- –> 表示依赖 !–> 表示不依赖
- 子绑定对象–>父绑定对象–>祖绑定对象(子可以依赖祖父) 父绑定对象 !–>子绑定对象 子绑定对象!–>同子绑定对象
Dependencies 依赖的使用
@Component为其依赖de @Component提供对象
public class Teacher {
public String name;
public int age;
}
@Module
public class TeacherMoudle {
@Provides
public Teacher provideFather(){
return new Teacher();
}
}
@Component(modules = TeacherMoudle.class)
public interface TeacherComponent {
Teacher getTeacher();//写抽象方法暴露依赖 Teacher
}
public class Student {
public String name;
public int age;
public Student(Teacher teacher) {
}
}
@Module
public class StudentMoudle {
@Provides
public Student provideChild(Teacher teacher){
return new Student(teacher);
}
}
//dependencies 表示 StudentComponent