Strictly speaking, the problem of interdependence between classes can be solved using interfaces (abstract classes, if your language, for example, C ++ or Python) IRoom and IPerson ; in pseudo code
interface IPerson IRoom getRoom()
this makes only the interfaces interdependent from each other - the actual implementation of the interfaces should depend only on the interfaces.
It also gives you a lot of implementation possibilities if you want to avoid cyclic reference cycles (which can be a problem, for example, in CPython by slowing down garbage collection) - you can use weak references, a basic relational database with a typical one-to-one table many ", etc. etc. And for the first simple prototype, you can use the simplest one in the language of your choice (perhaps a simple and, alas, necessarily circular, links [[pointers, C ++]] with Person referring to a Room and a Room to a list<Person> )
Alex martelli
source share