Currently I am struggeling on how - and if - to use attributes in a class that uses an interface.
In the past - when I designed an object - I used an interface and added the attributes I needed. Then a colleague stated that Interfaces should not have attributes for the following reasons:
all attributes will be PUBLIC
the implementing class should define by itself which attributes it uses
I know that the opinions about PUBLIC attributes are widely spread. Some say, that a class should not have any PUBLIC attributes. All data accesses should be done by GETTER methods. Others (like me) state that PUBLIC attributes are easy and flexible to use. Attributes can be easily changed. If I use GET and SET methods, then I will have the following two options:
read the data with GET method, store it in a local variable, and change the attribute by using the SET method.
Provide a special method for a change of that specific field.
Option 1 makes manipulating the data of the object more difficult as it could be.
The 2nd option requires that the object knows in advance what data the caller will be going to change.
I understand that providing GETTER and SETTER methods for a class is useful because the object has full control of it's data. The data cannot be manipulated so that some data might get invalid. But in 20 years of ABAP programming I have not often experienced that it was necessary that an object has the only control over its data.
Quite contrary to the experience that I as a caller of classes could not do the things that could be possible if the objects data was PUBLIC.
btw: Access by GETTER method is 100-150% slower than direct access of PUBLIC attributes...
What are your experiences, your thoughts and opinions about this topic?
"Security" IMO is overblown. Parameters are for programs, if you can see/read them then you are already running a program, programming, or debugging. Whenever I hear, e.g., RESTFUL is better than SFTP or "security" is compromised I always ask "how" and "why". To-date the replies have been "because" followed by technobabble gobblygook and at the end "company" policy. IMO use parameters as you like, I know that I will, that is why they are there.