OOP: When is it an object?

前端 未结 20 1341
悲哀的现实
悲哀的现实 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:32

    The textbook way of deciding on object granularity is to go by cohesion.

    If most of the methods of your object operates on most of the object's fields, then the object is small enough (For a given value of "most").

    An object is almost never too small.

提交回复
热议问题