It is important to remember that function calls provide a universal interface. Any object can interact with other objects using function calls. All you have to do is determine the correct signatures and leave. The only catch is that you have to interact exclusively through these function calls, which often work well, but can be inconvenient in some cases.
The main reason for directly displaying state variables is the ability to use primitive operators directly in these fields. If this is done well, it can increase readability and usability: for example, adding complex numbers with + or accessing the collection with the key using [] . The benefits of this can be surprising if your use of the syntax follows traditional conventions.
The trick is that operators are not a universal interface. Only they can be used only for a specific set of built-in types, they can only be used as required by the language, and you cannot define new ones. So, as soon as you defined your public interface using primitives, you locked yourself in using this primitive and only that primitive (and other things that can easily be attributed to it). To use anything else, you have to dance around this primitive every time you communicate with him, and this kills you from a harsh point of view: everything can become very fragile very quickly.
Some languages turn statements into a universal interface, but Java does not. This is not an accusation of Java: its developers decided to deliberately not include operator overloading, and they had good reasons for this. Even when you work with objects that seem to blend well with the traditional meanings of the operators, making them work in a way that actually makes sense, can be surprisingly nuanced, and if you don't completely nail it, you're going to pay for it later. It is often much easier to make a function-based interface understandable and usable than going through this process, and you often even get better results than if you were using operators.
However, there were compromises in this decision. There are times when the operator interface really works better than function-based, but without operator overloading, this parameter is simply not available. An attempt to force shoehorn operators to block you in any case in some design decisions that you probably really don't want them to be set in stone. The Java designers thought this compromise was worth it, and they might even be right. But such decisions do not come without any loss, and such a situation arises where the defeat falls.
In short, the problem is not to expose your implementation as such. The problem is to block yourself in this implementation.
The Spooniest Feb 20 '14 at 18:17 2014-02-20 18:17
source share