对象标识
From Apache OpenOffice Wiki
< Zh | Documentation
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
UNO 保证如果两个对象引用相同,将执行一项检查,并且不管返回 true 还是 false,始终产生正确结果。这与 CORBA 不同,后者返回 false 不一定意味着对象是不同的。
每个 UNO 运行时环境定义应该如何执行此检查。在 Java UNO 中,有一个静态 areSame() 函数,它位于 com.sun.star.uno.UnoRuntime 类中。在 C++ 中,通过 Reference<>::operator == () 函数执行检查,该函数在两个引用中查询 XInterface 并比较获得的 XInterface 指针。
这会对 API 设计产生直接的影响。例如,请看 com.sun.star.lang.XComponent:
interface XComponent: com::sun::star::uno::XInterface
{
void dispose();
void addEventListener( [in] XEventListener xListener );
void removeEventListener( [in] XEventListener aListener );
};
如果实现检查对象标识,则以侦听器引用为参数的方法 removeEventListener() 是合乎逻辑的,否则就无法标识需要删除的侦听器。CORBA 接口的设计方法与此不同。它们需要一个对象 ID,因为未保证对象标识。
| Content on this page is licensed under the Public Documentation License (PDL). |