OOP: When is it an object?

前端 未结 20 1340
悲哀的现实
悲哀的现实 2021-01-30 23:01

I\'m trying to understand object orientation. I understand it a little bit of course, but sometimes I\'m not 100% clear. How do you decide what should be turned into an object (

20条回答
  •  失恋的感觉
    2021-01-30 23:36

    As long as the object has only one purpose/responsibility is should not be divided anymore (unless it is too large which should not be the case).

    Make objects as long as you can divide and conquer them after that. If you make to many small objects you will not be able to handle well all. On the other other side to few big objects cannot be reused easily.

    My advice: practice! While practicing you will get a sense of what granularity you need - there is no general rule for this.

提交回复
热议问题