gpt4 book ai didi

c# - 术语 "true"面向对象是什么意思

转载 作者:数据小太阳 更新时间:2023-10-29 06:51:55 26 4
gpt4 key购买 nike

我听说过很多关于 Ruby,甚至可能是 Javascript 是“真正的”面向对象的语言,而不是 C++ 和 C#,后者是面向类(或基于模板)的语言。真正的 OO 是什么意思,它相对于类/模板方法有什么优势?

最佳答案

这是一个用于推广语言的主观术语。我曾经看到有人说,与 C++ 相比,C# 和 Java 是真正的面向对象语言,因为一切都必须在一个类中(没有全局函数或变量),并且所有对象都继承自一个 Object 类。

对于 Ruby,它可能指的是 Ruby 如何将一切都视为一个对象,因此您可以编写 1.to_s,而不是像 str(1)String.valueOf(1)。这是因为 Ruby 不区分值变量和引用变量。在 Javascript 中没有类,您只需创建可以克隆以供重用的可扩展对象,这种编程风格被称为 Prototype-based programming .

另一方面,C++ 被宣传为一种多范式语言,允许您使用多种方法,例如面向对象、泛型和过程编程。它不拘泥于一种范式。

但是,是的,这只是一个主观术语,可以表示任何意思。通常它指的是语言是否更强调对象而不是函数、模板等其他语言元素。Wikipedia's article on SmallTalk称其为“纯”面向对象语言,描述也适用于 Ruby:

Smalltalk is a 'pure' OO language, meaning that, unlike Java and C++, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. A programmer can change the classes that implement primitive values, so that new behavior can be defined for their instances--for example, to implement new control structures--or even so that their existing behavior will be changed. This fact is summarised in the commonly heard phrase "In Smalltalk everything is an object" (which would more accurately be expressed as "all values are objects", as variables aren't).

关于c# - 术语 "true"面向对象是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/250062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com