Object oriented programming - class design confusion

前端 未结 13 1972
你的背包
你的背包 2021-02-05 22:01

I am trying to wrap my head around object oriented programming.

My understanding is that we have objects so we can design our programs to mirror real-life objects.

13条回答
  •  迷失自我
    2021-02-05 22:22

    My understanding is that we have objects so we can design our programs to mirror real-life objects.

    Maybe more like 'relate' them to real life objects, where applicable.

    Should a fruit object rather be passed to a human object which has a Eat() function?

    Yes, or something more general than a human.

    I am trying to figure out the correct way to think about this. How closely, in general, should programming objects mirror real-life objects.

    Only define what you need to define. Then the implementation (typically) becomes very obvious. In other words, you're probably thinking too hard.

提交回复
热议问题