Standard object modelling identifies attributes, aggregates and associations of objects. You must conform to several requirements when implementing the equals() method of a class. There is plenty of advice available on how to write this method, including pitfalls to avoid. But I couldn’t find any advice indicating whether you should or should not examine associations when implementing equals(). It is clear to me that you should examine attributes and aggregates.
Should you examine associated objects in equals()? That is, should equality depend on associated objects?
While I think it is generally a good idea to avoid basing equality on associations, I would argue that this does not apply in all cases. While it is a good rule of thumb, there are likely a number of cases where this rule breaks completely.
It is entirely dependent on the domain and what it means for two objects to be equal. For example:
If you have a cohort of students, taught by a teacher, you could determine equality by requiring that another cohort must contain the same students be (pair-wise equal) and be taught by the same teacher. In that case, the cohort’s equality is strictly dependent on each of it’s pieces being equal.