Is OO design's strength in semantics or encapsulation?

后端 未结 11 1391
余生分开走
余生分开走 2021-01-30 23:28

Object-oriented design (OOD) combines data and its methods. This, as far as I can see, achieves two great things: it provides encapsulation (so I don\'t care what data there is,

11条回答
  •  花落未央
    2021-01-31 00:09

    Let's take a step back and look at this from a higher level. The advantages of any language feature lie in the ability to succinctly express the problem/solution in a more natural way with respect to the problem domain.

    The mechanics of OOP are easily implemented in plain C with structs and function pointers. You can even get a bit of OOP feel doing it that way. However, OOP idioms are not nearly as forthcoming in such an environment. When there's actual language support for OOP then the expressiveness of the paradigm comes out, and the way a language implements an idea has a very real impact on what is "said" and how. For example, see differences in code using closures/lambdas in lisp, python, ruby, etc.

    So in the end it's not about the components and underlying concepts, but rather how they're put together and used that make OO in C++ what it is.

提交回复
热议问题