例如,如果我有一堂课:
public class StuffHolder
{
List<Stuff> myList;
public StuffHolder()
{
myList = newList<Stuff>();
myList.Add(new Stuff(myList));
myList[0].stuffHappens();
}
}
和一个东西对象:
public class Stuff
{
List<Stuff> myList;
public Stuff(List<Stuff> myList)
{
this.myList = myList;
}
public void stuffHappens()
{
myList.Remove(this);
}
}
调用 stuffHappens() 而不是让 stuff 将应该删除的信息传递给 StuffHolder 类并让 StuffHolder 类删除特定的 Stuff 有什么缺点?