法VS功能VS程序VS类? [英] method vs function vs procedure vs class?

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

问题描述

我知道这个方法,程序,函数的基本知识和课程,但我总是搞不清那些面向对象程序设计的对比来区分,所以请任何机构可以告诉我,那些简单的例子之间的差异?

I know the basics of this methods,procedures,function and classes but i always confuse to differentiate among those in contrast of Object oriented programming so please can any body tell me the difference among those with simple examples ?

推荐答案

A ,目前,传统的OOP,与功能/程序捆绑在一起的数据的集合(成员变量)该数据(成员函数或方法)的工作。类有到其他三个术语除了这一事实没有关系,即它包含(更正确地相关联),后者

A class, in current, conventional OOP, is a collection of data (member variables) bound together with the functions/procedures that work on that data (member functions or methods). The class has no relationship to the other three terms aside from the fact that it "contains" (more properly "is associated with") the latter.

其他三个方面......嗯,这取决于。

The other three terms ... well, it depends.

A 功能是计算语句的集合。所以是一个程序即可。在一些非常肛门固语言,虽然,函数返回一个值和程序没有。在这样的语言中的程序,一般用于它们的副作用(如I / O),而函数用于计算和倾向于避免副作用。 (这是我倾向于使用。是的,我是肛门固)

A function is a collection of computing statements. So is a procedure. In some very anal retentive languages, though, a function returns a value and a procedure doesn't. In such languages procedures are generally used for their side effects (like I/O) while functions are used for calculations and tend to avoid side effects. (This is the usage I tend to favour. Yes, I am that anal retentive.)

大多数语言都不是肛门固,然而,作为结果的人会使用术语功能和程序可互换,preferring一个基于其背景的其他​​。 (调制*程序员会倾向于使用程序,而C / C ++ / Java的/不管会倾向于使用功能,例如。)

Most languages are not that anal retentive, however, and as a result people will use the terms "function" and "procedure" interchangeably, preferring one to the other based on their background. (Modula-* programmers will tend to use "procedure" while C/C++/Java/whatever will tend to use "function", for example.)

A 方式仅仅是绑定到一个类中的函数(或过程)的行话。事实上,并不是所有的OOP语言使用术语方法。在典型的(但不是万能!)实现,方法有一个隐含的第一个参数(称为东西像这个或类似物)用于访问包含类。这不,正如我所说的,普遍的。有些语言作出这样明确的第一个参数(从而允许被命名为任何你想),而还有一些人有没有神奇的第一个参数都没有。

A method is just jargon for a function (or procedure) bound to a class. Indeed not all OOP languages use the term "method". In a typical (but not universal!) implementation, methods have an implied first parameter (called things like this or self or the like) for accessing the containing class. This is not, as I said, universal. Some languages make that first parameter explicit (and thus allow to be named anything you'd like) while in still others there's no magic first parameter at all.

编辑补充这个例子:

下面的未经检验未编译 C ++ - 就像code应该告诉你什么样的事情都参与

The following untested and uncompiled C++-like code should show you what kind of things are involved.

class MyClass
{
  int memberVariable;

  void setMemberVariableProcedure(int v)
  {
    memberVariable = v;
  }

  int getMemberVariableFunction()
  {
    return memberVariable;
  }
};

void plainOldProcedure(int stuff)
{
  cout << stuff;
}

int plainOldFunction(int stuff)
{
  return 2 * stuff;
}

在此code getMemberVariableProcedure getMemberVariableFunction 有两种方法。

In this code getMemberVariableProcedure and getMemberVariableFunction are both methods.

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

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