In OOP, in what cases do you act on an object, rather than on an object acting?

In what cases or for what algorithms do you start using your objects as a data structure using methods outside the objects (i.e. Tree Walking, etc.).

Which circuit do you use? (Matching visitor patterns?)

Or do you think that an object should always be the only one who is allowed to act on its own data?

+4
source share
2 answers

Objects must bear a single responsibility. If the operation that you perform acts on the object, but has nothing to do with the responsibility of that object. Better to put it outside this object.

+1
source

Or do you think that an object should always be the only one who is allowed to act on its own data?

This is my philosophy (except for objects that are only entities, i.e. they map something else, for example, an xml file or something and contain only properties)

0
source

Source: https://habr.com/ru/post/1276963/


All Articles