“朋友”等同于Java? [英] 'Friends' equivalent for Java?

查看:110
本文介绍了“朋友”等同于Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在C ++中,我们有朋友的概念,这样的朋友类可以访问私人会员。



所以,我正在编写一个Java应用程序,并试图坚持MVC架构。我有一个控制器类来管理map_objects之间的图形连接。我想在DTO的map_objects中隐藏该功能,即通过使用此控制器类来实现这些连接。



(即使控制器类实现了设置连接性所需的功能,用户仍然可以直接访问DTO中的setter / getter函数来设置它们。)



在这方面是否有任何设计模式或提示?
(或者我完全死了?)



DUPLICATE 有没有办法在Java中模拟C ++的朋友概念?

(Un)幸运的是,在Java中没有直接的C ++朋友等效。但是, Java访问级别修饰符可以帮助您。特别是私人或私人包(AKA包保护或默认)可能有帮助。


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?

解决方案

(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.

这篇关于“朋友”等同于Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆