How best to resolve the PLO problem?

There are classes and University Professor.
University contains many instances of Professor.
At Professor should be getUniversity method that returns University.

As it is possible for the PLO to solve this problem? At the same time, Professor should not store a reference to the instance of the University, because it is aggregation, and the Professor can exist in the absence of the University, so the reference to the University may be always empty. Moreover, impaired SOLID principle (OCP): if in the future we want to add College and the Professor would have to work in two schools.
July 2nd 19 at 17:16
3 answers
July 2nd 19 at 17:18
And your method GetUniversity the Professor will not violate SOLID and aggregation? In my opinion there is the usual DI - injectivity dependence in the Professor, just not through the constructor and through the field, once the Professor can expect to run back and forth from University to College.
Imagine that the class of Professors writing for 3 years to Universities. And generally those who write the universities don't know that someone would write professors. And write them to different groups of people. And Professors -- is a modular structure that integrates different programs, not only at the Universities. - Ofelia72 commented on July 2nd 19 at 17:21
In other words: there is a group of people that says the Universities. They write them, and want to integrate them Professors. And Professors -- Namutoni class. But they need to be connected somehow to the universities. - Ofelia72 commented on July 2nd 19 at 17:24
The method will break it, but I brought it up as an example. Need something through the Professor to go to the University where he currently is. There are more effective ways than just through Universities? - Ofelia72 commented on July 2nd 19 at 17:27
time professors write for 3 years to universities, then the Professor should not be any method GetUniversity, nor even links to the University. Here are two options - either the University is the method of the "IsProfessorInUniversity" taking a pointer to the Professor, or even a separate class, head of all these connections. - nicklaus commented on July 2nd 19 at 17:30
Here. I'm asking how best to organize from the point of view of OOP all these heads of communication. Is there a better way than just cycle take place in the Universities? - Ofelia72 commented on July 2nd 19 at 17:33
an external class which has a dictionary where the key is the Professor, and the value is a list of the institutions where he works. And will without a search. - nicklaus commented on July 2nd 19 at 17:36
This is certainly enough to spike the decision - good for you then all methods. responsible for a bunch of professors and Universities need to keep in this class. - nicklaus commented on July 2nd 19 at 17:39
: Is there a way to keep a direct reference to the University anywhere? - Ofelia72 commented on July 2nd 19 at 17:42
don't understand the question. I'm above the structure you have described, in which direct links to the universities. - nicklaus commented on July 2nd 19 at 17:45
July 2nd 19 at 17:20
University contains many instances of Professor.


I mean? The University can give rise to many instances of universities, and the Professor - professors. And they can't inherit - the Professor has no properties or methods of the University.

As rightly suggested by the colleague above, belonging to the University - a common property of the Professor, and may be many-to-many. Consequently, the answer to your question: normal getter.
The content of many instances -- a collection of professors as a field in each instance of the University. - Ofelia72 commented on July 2nd 19 at 17:23
I incorrectly cited a method in an example. Professors -- namutoni class. If the College will create after the professors write, they can no longer rule and to write "getters". - Ofelia72 commented on July 2nd 19 at 17:26
: the University lacks a tuple in professors. There are train connections - Ofelia72 commented on July 2nd 19 at 17:29
July 2nd 19 at 17:22
1 . To make a separate array of dictionaries university - professor. When you receive College, you will need another array of college-professor. To search will need to cover the whole array. To change the class Professor will not need the appearance of colleges.
2. To store an array of professors at every College and University an array of each Professor. When you add kaleida will need to change the class of the Professor.

The first solution is more versatile, corresponds to the normal forms of database design and is often used in the design of the database, meaning when you see the database, as it apparently appears, to move all in the DB will be easy.

Find more questions by tags OOPProgramming