Who will take on the role of Friend functions in java, like in C ++?

Who will take on the role of Friend functions in java, like in C ++? How will this work in java?

Thank..

+3
source share
4 answers

The next version of Java for C ++ friends is the default access modifier, also known as a protected package or closed package. This allows access to members from only other classes within the same package.

This is also the best reason for placing classes in one package, and not for grouping into subpackages based on functionality.

+8
source

Java -. , Java - ( ) -

+7

, . Java . , , , , . , Friend OO. ++ , OO, , OO.

I would think about changing your design to bring functionality closer to where the data lives, then you really will not have this problem. However, this is not always possible, especially if you are working with an outdated system. In this case, you should consider adapter classes, getters and setters, or parameters. Only my two cents.

0
source

The friend function is a flaw in the concept of OOP because it is used to access the function of a member of a class from the outside. This is why it was removed from Java.

0
source

Source: https://habr.com/ru/post/1729437/


All Articles