Re: Is a class a friend of itself?
Alan Woodland <ajw05@aber.ac.uk> writes:
I think this assumption comes from the 'Java Bean' way of thinking about
interfaces, data and objects. I've definitely seen this question a lot
from Java programmers. Which is odd because Java allows the exact same
thing...
One can also view it from the point of the decorator
pattern.
A decorator object wraps a core object. Now, think of the
decorator object as the ?main? object: This main object
contains a core object, which in turn contains core
fields, but the main object can not access ?its? core
fields directly, but only via the methods of the core
object.
This sometimes comes in handy so as to structure the
methods of an object into ?core methods? and ?hull
methods?. For example, when the object wraps an external
device and this devise changes, the source code of the
object needs to be modified to reflect the changes.
Sometimes, this can be done by only changing the core
methods. So, in this case, this separation helps to easily
find the part of the source code that needs to be
adjusted.