Wikipedia上面关于Method stub的说明

Method stub

From Wikipedia, the free encyclopedia

method stub or simply stub in software development is a piece of code used to stand in for some other programming functionality. 

软件开发中的“方法存根”或者“存根”是一段为了保证其它程序功能运行的替代代码块。

A stub may simulate the behavior of existing code (such as a procedure on a remote machine) or be a temporary substitute for yet-to-be-developed code. 

“存根”会模拟已有代码(例如远程机器上的一段程序)的逻辑或者成为待开发代码的临时替代者。

Stubs are therefore most useful in portingdistributed computing as well as general software development and testing.

“存根”因此经常被用于程序移植、分布式计算和常规的软件开发和测试中。

An example of a stub in pseudocode might be as follows:

关于“存根”的一段伪代码如下:

   BEGIN
       Temperature = ThermometerRead(Outside)
       IF Temperature > 40 THEN
            PRINT "It's HOT!"
       END IF
   END
   BEGIN ThermometerRead(Source insideOrOutside)
        RETURN 28
   END ThermometerRead

The above pseudocode utilises the function ThermometerRead, which returns a temperature. 

上面的伪代码就利用了ThermometerRead函数返回了温度值。

While ThermometerRead would be intended to read some hardware device, this function currently does not contain the necessary code. 

然而ThermometerRead函数本该要去读取某些硬件设备的参数,但这个函数中并没有包含所需的代码。

So ThermometerRead not, in essence, simulate any process, yet it does return a legal value, allowing the main program to be at least partially tested. 

因此ThermometerRead函数体从根本上来说并没有模拟任何的过程,只是返回一个合理的数值,这个值从一定程度上可以保证主程序的可测性。

Also note that although it accepts the parameter of type Source, which determines whether inside or outside temperature is needed, it does not use the actual value passed (argument insideOrOutside) by the caller in its logic.

值得注意的是:虽然函数具有Source类型的参数,它可以决定是否需要传递内部或者外界温度,但是函数内部并没有使用调用者在主程序中传递进去的参数。

A stub [1] is a routine that doesn't actually do anything other than declaring itself and the parameters it accepts and returning something that is usually the values expected in one of the "happy scenarios" for the caller. 

“存根”在编程中较为常见,它除了声明函数、函数参数以及返回对于调用者来说在程序“正常执行过程”中预期的值之外并没有其它任何作用。

Stubs are used commonly as placeholders for implementation of a known interface, where the interface is finalized/known but the implementation is not yet known/finalized.

“存根”经常作为实现一个已知接口的占位标志,这个接口的声明通常是一个不可更改或者广为熟知的名字但该接口并未有实现类或者实现类未被终极化。

The stub contains just enough code to allow it to be compiled and linked with the rest of the program. In RMI nomenclature[2], a stub communicates on the server-side with a skeleton.[3]

“存根”中具有足够的代码能够通过编译并和程序中其他单元有一定联系。在RMI命名法中,“存根”将会与架构在服务端进行交互。

~~~~~~~~~~~~~~~~~~~~~~~~~~如有不当之处,敬请各位指正!~~~~~~~~~~~~~~~~~~~~~~~~~~

[1]."stub".WEBOPEDIA. Retrieved 2012-08-28.

[2].[RMI nomenclature] Remote Method Invocation nomenclature远程方法调用命名法

[3].Freeman, Eric; Freeman, Elisabeth; Kathy, Sierra; Bert, Bates (2004). Hendrickson, Mike; Loukides, Mike, eds. Head First Design Patterns (paperback) 1. O'REILLY. p. 440. ISBN 978-0-596-00712-6. Retrieved 2012-08-28.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值