I think it is common to other languages like Java or c# also . An instance of class cannot access instance variable of another instance of same class. How it is specific to smalltalk only ?
Sorry, but this thinking is incorrect.
In Java, an instance of a class can access the private fields of another instance of the same class.
For a class Point
with two fields x
and y
, a common implementation of the equals
method (in fact generated by Intellij) is:
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
if (x != point.x) return false;
if (y != point.y) return false;
return true;
}
In this, the current object is accessing the fields of the other object point
directly, as would not be allowed in Smalltalk.
This is also allowed in C# and many other languages. Whether Smalltalk is really the only language disallowing it I'm not sure.
By convention, the accessors of a Smalltalk class frequently are the same as the instance variable, but you need to actually write the accessors, and there is no syntax for accessing fields on a different instance directly.