Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我处理 OO 已经好几年了,有时我会看到一个类,它有一个属性(通常是列表或表),它包含对自身和其他相同类型对象的引用。
这种模式有名字吗?使用它的通常情况是什么,为什么?
提前谢谢。
It is a very usual case. For instance a table which contains a foreign key to itself :
Employee ---------- ID MANAGER_ID (reference to employee)
Your JPA/Hibernate entities will hold references to themselves when you are your own boss :-)