Difference between revisions of "Zh/Documentation/DevGuide/ProUNO/Singletons"
From Apache OpenOffice Wiki
< Zh | Documentation
(New page: {{Documentation/DevGuide/ProUNOTOC/Zh |ProUNO2a=block |ProUNO2aDTypes=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/ProUNO/Exceptions |NextPage=Zh/Documentation/DevGuide/Pr...) |
m |
||
Line 6: | Line 6: | ||
|NextPage=Zh/Documentation/DevGuide/ProUNO/Understanding the API Reference | |NextPage=Zh/Documentation/DevGuide/ProUNO/Understanding the API Reference | ||
}} | }} | ||
− | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}} | |
{{DISPLAYTITLE:Singletons}} | {{DISPLAYTITLE:Singletons}} | ||
Latest revision as of 01:59, 14 May 2009
Singleton 用于指定已命名对象,在一个 UNO 组件上下文的生存期中恰好可以存在一个实例。singleton 引用一个接口类型,并指定只能在组件上下文中通过使用 singleton 名称来访问 singleton 唯一存在的实例。如果该 singleton 不存在实例,组件上下文将实例化一个新的实例。这种新式 singleton 的一个示例如下
module com { module sun { module star { module deployment { singleton thePackageManagerFactory: XPackageManagerFactory; }; }; }; };
各个语言绑定提供了在给定组件上下文的情况下,可得到新式 singleton 实例的特定语言方法。例如,在 Java 和 C++ 中,有一个名为 get 的静态方法(resp. 函数),该方法将 XComponentContext 作为其唯一的参数,并返回(适当键入的) singleton 实例。如果无法得到实例,则会抛出 com.sun.star.uno.DeploymentException。
此外,还有旧式 singleton,这些 singleton 引用的是(旧式)服务而不是接口。但是,对于旧式服务,语言绑定不提供 get 功能。
Content on this page is licensed under the Public Documentation License (PDL). |