【发布时间】:2013-11-05 14:45:03
【问题描述】:
我正在开发一个 CAD 应用程序,其中有块实体。每个块实体都有一个子实体列表。 When these entities are rendered, every block entity knows about its child entity (as it can figure out the child entity in the list), and hence when block entity is selected, the whole block entity along with its child entities gets selected.但是,子实体不知道该块的父块和其他子实体,并且由于选择了子实体时,我无法将整个块实体以及所选的所有子实体一起获取。
为了解决这个问题,我在子实体中创建了一个属性来保存父块实体的引用。但是,交叉引用可能会出现一些问题,并使我的数据结构容易出错。
例如:有一个复制命令,几天后处理这些数据结构的人可能只是在创建子实体的副本时复制同一个父实体。但是,新副本应该属于其他父块。
请提出更好的方法来实现这种关系,以便在选择子实体时我可以选择整个块实体及其所有子实体。
public class BlockEntity
{
public List<ChildEntity> Children = new List<ChildEntity>();
}
public class ChildEntity
{
public readonly BlockEntity Parent;
}
【问题讨论】:
-
寻找脱节的集合结构和联合查找算法