OOP: When is it an object?

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

    I answered this already in another question

    Code objects are not related to tangible real-life objects; they are just constructs that hold related information together.

    Don't believe what the Java books/schools teach about objects; they're lying.

    Just write something that gets the job done, even if it's ugly, then refactor continuously:

    • eliminate duplicate code (don't repeat yourself)
    • increase cohesion
    • reduce coupling

    But:

    • don't over-engineer; keep it simple
    • don't write stuff you ain't gonna need

    If you don't end up with massive (and useless) class hierarchy, then you have done a good job, producing elegant and clean code.

    Remember: OOP is a means, not an end.

提交回复
热议问题