Should an object write itself out to a file, or should another object act on it to perform I/O?

后端 未结 7 1716
予麋鹿
予麋鹿 2020-12-23 02:06

NOTE: Sorry for the long question!

I\'m trying to understand some key areas behind object orientation and I couldn\'t decide one way or another about my par

7条回答
  •  不思量自难忘°
    2020-12-23 02:35

    I would make Bob know how to serialize itself since it has private data. Another object (such as your Writer) would take that and put it on disk. Bob knows how to deal with its data best but it need not care about how or where that is stored. Your Writer knows how to save data best but it need not care about how that data is created.

提交回复
热议问题