Java 和 Ruby:“一切皆对象"在面向对象? [英] Java and Ruby: "everything is an object" in OO?

查看:48
本文介绍了Java 和 Ruby:“一切皆对象"在面向对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的一切都是对象吗,就像在 Ruby 中一样?

Is everything in Java an object, the way it is in Ruby?

书籍、教程、一切都说明Ruby 中的一切都是对象",但这在面向对象的语言中很常见吗?

Books, tutorials, everything states "everything in Ruby is an object", but is that common for object oriented languages?

对象是否也是 Java,或者面向对象只是一种编程范式,并不意味着一切都是对象或计算为对象?

Is everything an object is Java as well, or is object oriented just a paradigm of programming, and it doesn't mean that everything is or evaluates to an object?

推荐答案

没有

而言,原始类型"(intboolfloat 等.) 在 Java 中不是对象.在 Ruby 中,它们是对象.(在一些 Ruby 实现中,fixnums 在内部是为了提高性能的值类型",但在外部它们可以被视为具有方法的真实"对象).

As far as values go, the "primitive types" (int, bool, float, etc.) in Java are not objects. In Ruby they are objects. (In some Ruby implementations fixnums are "value types" internally for performance, but externally they are treatable as "real" objects that have methods).

此外,还有一些在 Ruby 中是对象而不是在 Java 中的对象,例如类.(实际上,Java 也将这些作为 Class 公开,但意义不同.)

In addition, there are other things that are objects in Ruby that are not objects in Java such as classes. (Actually, Java exposes these as Class as well, but in a different sense.)

有些东西在这两种语言中都不是对象,例如变量方法.(虽然在 Ruby 中很容易获得代表给定方法的对象.)

There are some things that are not objects in either language, such as variables and methods. (Although in Ruby it is easy to get an object that represents a given method.)

无论如何,我认为更大的图景是面向对象的编程范式呈现了一个way 对数据进行分组和对所述数据进行操作.(这通常是通过实例方法来完成的,就像在 Java 和 Ruby 中一样,尽管它也可以通过 多重分派 和其他语言来完成,比如 Haskell,它是非 OO",为此任务提供替代方法.)

Anyway, I think the bigger picture is that the Object Oriented programming paradigm presents a way to group data and operations on said data. (This is generally done through instance methods, as in Java and Ruby, although it might also be done through multiple dispatch and other languages, like Haskell which is "non-OO", offer alternative approaches to this task.)

OO"的定义通常还包括继承"、封装"、抽象"等愚蠢的教科书术语,但不同OO"语言的用法和模式可能差异很大,并且与非面向对象"语言 ;-)

Often times the definition of "OO" also includes "inheritance", "encapsulation", "abstraction", and other silly textbook terms, but the usage and patterns of different "OO" languages can vary greatly and overlap those found in "non-OO" languages ;-)

这篇关于Java 和 Ruby:“一切皆对象"在面向对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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