- 仅仅和朋友交流(更准确来讲是:直接的朋友)
- 朋友之间也有间距
因此,要适时重复衡量:能否够降低public方法和属性,改为private、package-private、protected等訪问权限。及能否够加上finalkeyword。
public class Teacher { public void commond(GroupLeader groupLeader) { List<Girl> listGirls = new ArrayList<Girl>(); for (int i = 0; i < 20; i++) { listGirls.add(new Girl()); } groupLeader.countGirls(listGirls); } }
public class Teacher { public void commond(GroupLeader groupLeader) { groupLeader.countGirls(); } } public class GroupLeader { private List<Girl> listGirls; public GroupLeader(List<Girl> _listGirls) { this.listGirls = _listGirls; } public void countGirls() { System.out.println("女生数量是:" + listGirls.size()); } }