Implementing Composition in Java
问题 class Book { private Chapter[] chapters = new Chapter[5]; } class Chapter { private Book book; } Is this the correct way to implement the above relationship? I need explanation on this. Thanks. 回答1: That is not enough. In Composition relationship, If whole instance is destroyed, the part instance should also be destroyed immediately . You should have some codes (some machanisms) to do that. For example if you push the instances of Chapter s from external the class (for example by using a