标签:
迪米特法则:(Law of Demeter, LoD),也称最少知识原则(Least Knowledge Principle, LKP)
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()); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u014034854/article/details/46777061