Java的方法与功能 [英] Java's methods vs. functions

查看:100
本文介绍了Java的方法与功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是决定将我的MATLAB编程技能与一些更一致和严格的Java编码整合在一起。因此,我希望这不会是一个太天真的问题。



我想知道是否有任何真正的原因为什么Java引用函数为方法而不是函数,就像许多其他程序语言一样。 是因为与 C / C ++ 等过程语言相比,Java的本质是内部的 OOP 或者是否有其他重要的(或微妙的)原因?



预先致谢。

解决方案

在我看来这个图
有助于理解OO和程序编程之间的主要区别之一。
基本上这个想法是:


程序设计只提供一个维度来将
计算单位与名称关联起来。在这里,过程调用或名称
直接映射到过程实现。在图中,一个调用
m1别无选择,只能调用
过程的唯一实现m1


while


面向对象编程为名称解析
增加了程序编程的另一个维度。除了方法或
过程名称外,消息调度在查找方法时将消息接收器转换为
考虑因素。在图2b中,我们看到了方法m1的两个
实现。选择合适的方法
不仅取决于消息名称m1,而且还取决于
的接收者实际的消息,这里Ry

$ b $ (c)的第三部分涉及面向主题的编程,其中对象(被调用的方法)的行为不仅取决于对象状态,而且也取决于主体它正在调用(或观察)它。但是这实际上超出了你的问题的范围。

I just decided to integrate my MATLAB programming skills with some more consistent and rigorous Java coding. Therefore I hope it's not gonna be a too naive question.

I'd like knowing if there is any real reason why Java refers to functions as methods and not as functions, as many other program languages do.

Is it because of the inner OOP Java's nature compared with procedural languages such as C/C++? or are there any other important (or subtle) reasons?

Thanks in advance.

解决方案

In my opinion this figure http://www.jot.fm/issues/issue_2008_03/article4/images/figure2.gif

from http://www.jot.fm/issues/issue_2008_03/article4/ helps understanding one of the main differences between OO and procedural programming. Basically the idea is that

Procedural programming provides only one dimension to associate a computational unit with a name. Here, procedure calls or names are directly mapped to procedure implementations. In Figure a calling m1 leaves no choice but the invocation of the only implementation of procedure m1

while

Object-oriented programming adds another dimension for name resolution to that of procedural programming . In addition to the method or procedure name, message dispatch takes the message receiver into consideration when looking up a method. In Figure 2b we see two implementations of method m1. The selection of the appropriate method not only depends on the the message name m1, but also the receiver of the actual message, here Ry

the third section of the figure (c) refers to subject oriented programming, in which the behavior of an object (the called method) does not only depend on the object status but, also, on the subjects which is invoking (or observing) it. However this is actually out of the scope of your question.

这篇关于Java的方法与功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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