having a little architectural trouble here.
In C++, we have the notion of 'friends,' where such friend classes can access private members.
So, I'm deving a Java app and trying to adhere to the MVC architecture. I've got a controller class that manages graph connectivity between 'map_objects.' I'd like to hide the function in the DTO 'map_objects' that actuall sets up these connectivities, by using this controller class.
(Ie, even if the controller class implements the required functionality of setting up connectivities, the 'users' can still access setter/getter functions in the the DTO directly to set them up themselves.)
Are there any design patterns or tips in this regard? (Or have I totally mucked up?)
DUPLICATE Is there a way to simulate the C++ 'friend' concept in Java?
You might want to use interface segregation - that is, let the class implement different interfaces, and only pass out references to the appropriate (smaller) interfaces to the different clients.
(Un)fortunately, there is no direct C++ friend equivalent in Java. However, the Java access level modifiers can assist you. In particular, private or package private (AKA package protected, or "default") may help.