OOP 的意义何在? [英] What's the point of OOP?

查看:19
本文介绍了OOP 的意义何在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,尽管在 OOP 教育、语言和工具上花费了数百万或数十亿美元,但 OOP 并没有提高开发人员的生产力或软件可靠性,也没有降低开发成本.很少有人在严格意义上使用OOP(很少有人坚持或理解LSP等原则);人们对问题域建模的方法似乎没有什么统一性或一致性.很多时候,这个类只是因为它的语法糖而被使用;它将记录类型的函数放入它们自己的小命名空间中.

As far as I can tell, in spite of the countless millions or billions spent on OOP education, languages, and tools, OOP has not improved developer productivity or software reliability, nor has it reduced development costs. Few people use OOP in any rigorous sense (few people adhere to or understand principles such as LSP); there seems to be little uniformity or consistency to the approaches that people take to modelling problem domains. All too often, the class is used simply for its syntactic sugar; it puts the functions for a record type into their own little namespace.

我为各种应用程序编写了大量代码.尽管在某些地方,真正的可替代子类型在应用程序中发挥了重要作用,但这些都非常出色.一般而言,尽管谈论重用"时有很多口头上的说法,但事实是,除非一段代码完全完成您想要它做的事情,否则几乎没有成本效益的重用"-利用".将类设计为以正确的方式可扩展是极其困难的,因此扩展的成本通常非常高,以至于重用"根本不值得.

I've written a large amount of code for a wide variety of applications. Although there have been places where true substitutable subtyping played a valuable role in the application, these have been pretty exceptional. In general, though much lip service is given to talk of "re-use" the reality is that unless a piece of code does exactly what you want it to do, there's very little cost-effective "re-use". It's extremely hard to design classes to be extensible in the right way, and so the cost of extension is normally so great that "re-use" simply isn't worthwhile.

在许多方面,这并不让我感到惊讶.现实世界不是面向对象",面向对象中隐含的想法——我们可以用某种类分类法对事物进行建模——在我看来是非常有根本缺陷的(我可以坐在桌子上、树桩上、汽车引擎盖上),某人的膝盖——但其中一个不是——椅子).即使我们转向更抽象的领域,面向对象建模通常也很困难、违反直觉,最终也无济于事(考虑圆形/椭圆或正方形/矩形的经典示例).

In many regards, this doesn't surprise me. The real world isn't "OO", and the idea implicit in OO--that we can model things with some class taxonomy--seems to me very fundamentally flawed (I can sit on a table, a tree stump, a car bonnet, someone's lap--but not one of those is-a chair). Even if we move to more abstract domains, OO modelling is often difficult, counterintuitive, and ultimately unhelpful (consider the classic examples of circles/ellipses or squares/rectangles).

那么我在这里错过了什么?OOP 的价值在哪里?为什么所有的时间和金钱都未能让软件变得更好?

So what am I missing here? Where's the value of OOP, and why has all the time and money failed to make software any better?

推荐答案

没有经验证据表明面向对象是人们思考世界的更自然的方式.编程心理学领域的一些工作表明,面向对象并不比其他方法更合适.

There's no empirical evidence that suggests that object orientation is a more natural way for people to think about the world. There's some work in the field of psychology of programming that shows that OO is not somehow more fitting than other approaches.

面向对象的表示似乎并不普遍更有用或不太有用.

Object-oriented representations do not appear to be universally more usable or less usable.

仅仅采用面向对象的方法并要求开发人员使用此类方法是不够的,因为这可能会对开发人员的生产力以及所开发系统的质量产生负面影响.

It is not enough to simply adopt OO methods and require developers to use such methods, because that might have a negative impact on developer productivity, as well as the quality of systems developed.

出自关于面向对象表示的可用性";来自 ACM 通讯 2000 年 10 月.这些文章主要将 OO 与面向过程的方法进行了比较.有很多关于使用 OO 方法工作的人如何思考"的研究.(Int. J. of Human-Computer Studies 2001, issue 54, or Human-Computer Interaction 1995, vol. 10 有一个关于 OO 研究的完整主题),从我读到的,没有任何东西表明某种自然性OO 方法,使其比更传统的程序方法更适合.

Which is from "On the Usability of OO Representations" from Communications of the ACM Oct. 2000. The articles mainly compares OO against theprocess-oriented approach. There's lots of study of how people who work with the OO method "think" (Int. J. of Human-Computer Studies 2001, issue 54, or Human-Computer Interaction 1995, vol. 10 has a whole theme on OO studies), and from what I read, there's nothing to indicate some kind of naturalness to the OO approach that makes it better suited than a more traditional procedural approach.

这篇关于OOP 的意义何在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆