Hi!
Quote:
The problem is that a People can be a Policeman AND a Scientist or not. A People can be a Scientist AND a Policeman.
Then definitely you should be using composition instead of inheritance:
Person to One Relationship to Doctor
Person to One Relationship to Policeman
Quote:
So a people could be a policeman AND a scientist and that's not multiple inheritance because the Scientist, Policeman classes inherit of only one class : People.
I am sad to tell you, but it is multiple inheritance, because you want your people object to be at the same time of the types of two different classes (Policeman and Doctor) and to do that, you would need a third type, a type that inherits from both Policeman and Doctor, and that would have to be the type of your object.
Imagine you are not working with NHibernate, just plain C#, and you will see that what you want is plain impossible to do (without composition or multiple inheritance):
Code:
Policeman pol = new Policeman();
Policeman doc = new Doctor();
Person p = por; // Fine it works because a Policeman is a Person
Person d = doc; // Fine it works because a Doctor is a Person
But then try:
Code:
Policeman cop = new Doctor(); //It doesn't work
Doctor medic = (Doctor) pol; //It doesn't work AFAIK it doesn't compile, but if it does, it will throw an InvalidCastException on runtime
You see? if it can't be done in C#, it can't be done in NHibernate. It would of course work in unmanaged C++ (by creating a new DoctorPolice class that inherits from both Police and Doctor, but NHibernate wasn't designed to work with unmanged C++)