代码对象示例以及概述。
使您的代码对象和面向服务。
下一节将介绍如何在代码中查找这些对象。
The next section covers how to look up these objects in code.
下面的示例代码假设此对象存在。
接着您希望执行使用这个对象模型的代码文件。
You then want to execute files of code that consume that object model.
然后再编写代码来绘制这些对象。
接下来,将了解如何在代码中查找这些对象。
清单4显示了测试用例对象的完整代码。
在测试代码中,创建模仿对象且实现与合作者相同的接口。
In your test code, create a mock object implementing the same interface as the collaborator.
该代码向对象添加了一个连接的名字和值。
通过声明为静态,为客户机代码节省了创建对象的工作量。
By declaring it static, you save client code the overhead of creating an object.
清单3给出模拟设备对象的代码。
我们的测试代码,特别是模拟对象,使我们能完全控制数据库结果。
Our test code, specifically the mock objects, give us total control over the database results.
如果调用一个对象的方法,代码也被添加到内部缓冲区中。
If you call an object's method, the code is added to the internal buffer.
输入以下代码,将对象更改保存到数据库。
Enter the following code to save object changes to the database.
以下代码示例使用业务对象类。
补救方法是更改代码,以强制转换为正确的对象。
The remedy is to change the code to cast correctly to the right object.
图1显示了每行代码执行后各对象的状态。
Figure 1 shows the state of the objects after each line of code executes.
示例代码生成许多这样的新对象,并且它们很快就被收集掉。
The sample code generates a lot of those, and they are quickly collected.
在图1中,客户机代码通过接口使用服务器对象。
In Figure 1, the client code makes use of a server object through its interface.
创建此对象的代码如清单14所示。
下面的示例代码填充输入数据对象。
Here is some sample code that populates the input data object.
如果放置了过少的互斥对象,代码将出现奇怪和令人尴尬的错误。
If you place too few, your code will have weird and embarrassing bugs.
还需要编写代码来让这些对象可以随着时间的推移而到处移动。
以下代码给出了访问location对象的信息的方法。
The following code shows how information for the location object is accessed.
使用mock对象的测试代码。
Ksplice更容易处理这种“模块化”对象代码。
Such "modular" object code is more easily manipulated by Ksplice.
我们在此编写的代码块位于名为BuddyNoteServerStorage的对象中。
The bulk of the code that we write here is in an object called BuddyNoteServerStorage.
这两行代码提供了对Selection对象的引用。
These two lines of code provide a reference to the Selection object.
这两行代码提供了对Selection对象的引用。
These two lines of code provide a reference to the Selection object.
应用推荐