I must agree but only because it seems to be the same in other languages.not a bug
Did you read that "I" have access to the private members of instances of a class from within a single instance of that same class?I haven't read all posts
Even the developer who created the class should have the advantages of encapsulation, to avoid making mistakes, so he shouldn't have the ability to access private members of an object, even if he has developed the base class.I think the point is not to make the methods private in an absolute sense, but to external classes that could make an unexpected use of them.
But it is possible that all instances of the class see all private methods, because it is the same developer who created the class that operates on those variables and not an external class / developer
In which case I think you might have missed the missed the point, as I did originally. It is not about encapsulation but about class level versus instance level access to private instance variables. Instances of a class can access the private items of another instance of the same class. @LucaMs seems to think this is wrong, despite it being a long standing feature of many languagesI haven't read all posts but
Yes, I think it is wrong, because an OBJECT has its own private members which should be such in any "environment", otherwise it is no longer a closed box, a black box, of which you must have the right to access only its public members.@LucaMs seems to think this is wrong, despite it being a long standing feature of many languages
True, but I will try to explain why it is like this.Anyway, that's the way things are, I can not do anything but accept it
I really appreciate this, that you still specify even though you know my bad habit of wanting to argue... a little too much ?True, but I will try to explain why it is like this.
Yes, one of the fundamentals of objects is encapsulation, their interface is the contract you mentioned and I agree.Think about classes inside a library, such as XUI Views. The public members are a contract between me, the developer who is writing the library, and the developer who is using it.
I cannot change the signature of any public sub without breaking code of many developers
I agree less on this. It is true that in that way you have more freedom, the possibility of accessing a private member of an object based on your class, but it can also be a source of errors, if you inadvertently use a private member thinking that it is public.There is no reason to limit the class developer from accessing all members. It is very useful.
The check of the contents of the two objects is right to be done on the properties of them.@lucas, how would you handle an Equals method with your methodology?
Class Test
Priv a
Pub b
Public Sub Equals(obj As Test)
if b = obj.b And a = obj.a then return True
Return False
End Sub
In your case the variable 'a' would need to be made public, defeating the reason of keeping it private.
It seems to me that the answer was clear, another instance of the same object is not considered another object.I sent a friend a link to a tutorial on object-oriented programming (he learned it in a "practical" way, so he gets a little confusing in the distinction between class, object, instance, ...).
Well, just to see if I still remember everything and to pass the time, I started reading it myself!
Sentence in that tutorial:
(Italian)
Inoltre, un oggetto non dovrebbe mai manipolare direttamente i dati interni (le proprietà) di un altro oggetto ma ogni tipo di comunicazione tra oggetti dovrebbe essere sempre gestita tramite l’uso di messaggi, ovvero tramite le chiamate ai metodi che un oggetto espone all’esterno.
(English)
Furthermore, an object should never directly manipulate the internal data (the properties) of another object but any type of communication between objects should always be managed through the use of messages, i.e. through the calls to the methods that an object exposes to the external.
I would have added: "not even if the "manipulator object" is an object of the same class"
Just for... fun?Now since all languages implement them like this, why lengthen this thread again?
Yes, but to have fun there must be someone who counters you. ? ? ?Just for... fun?
Okay, I admit it: I hate this thing, which I wouldn't call "feature" at all.Now since all languages implement them like this, why lengthen this thread again?
Better if you write to Steve Jobs, you will have more listeningOkay, I admit it: I hate this thing, which I wouldn't call "feature" at all.
I will write to Bill Gates, James Gosling, Guido van Rossum, ... Joe Biden and I will make sure that this is changed in all programming languages; even in those who are not object oriented!
?
I had thought about it, I wanted to create a language that would allow me to write applications for Android in a similar way to VB Net; obviously it would have generated Java code.However think about creating a new language, it is not difficult
Please send it by fax.Okay, I admit it: I hate this thing, which I wouldn't call "feature" at all.
I will write to Bill Gates, James Gosling, Guido van Rossum, ... Joe Biden and I will make sure that this is changed in all programming languages; even in those who are not object oriented!
?
P.S. and to Erel