Should I use whole objects or only object IDs as data members of class?

Viewed 51

I was looking at some of the LLD interview preparation codes, I found they use data members id or objects interchangeably. I want to understand when should I use each of them.

For Example ->

Class Teacher {
  int id,
  list<Student> students
}
Class Teacher {
  int id,
  list<int> students
}

first code uses Student object to to hold info about students in Teacher class wheareas second code only hold IDs of students and using which student objects can be queried.

0 Answers
Related