Wrapping instance variables in accessor methods

298 views Asked by At

Sandy Metz says (POODR book, page 26):

Because it is possible to wrap every instance variable in a method and to therefore treat any variable as if it's just another object, the distinction between data and a regular object begins to disappear.

I am not sure if I understand what she is explaining. When we define the accessors, we are wrapping the instance variables (data) on a method but methods are not objects. So what does she mean when she says that we can treat variables as if they're just another object?

1

There are 1 answers

0
fylooi On

The primary difference between data and objects is behaviour. Objects can modify their internal state without changing their interfaces, while data are static structures.

When we wrap data access within a method, we get the same benefits of an object - the interface remains static to consumers even if the underlying data structure needs to change.