I have three classes-A,B,C in java. Conditions-
- A can access members of B and C
- B can access members of C
- C cannot access members of A and B
- B cannot access members of A
If I declare members of B,C as protected and put all the classes in a package, I won't able to enforce the 3rd and 4th condition. What should be the approach here?
I can see that most of the answers mentioned that I can directly do inheritance like A <- B <- C. But, lets assume we have classes like patient and doctor. So, doctor needs to know the details a patient given a patient id. Implementation wise If I extend doctor from patient, that will solve the use case. But, logically it doesn't make sense to me to extend doctor from patient as doctor is not a patient.