Difference between revisions of "Documentation/DevGuide/ProUNO/Singletons"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m (FINAL VERSION FOR L10N)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/ProUNO/Understanding the API Reference
 
|NextPage=Documentation/DevGuide/ProUNO/Understanding the API Reference
 
}}
 
}}
[[zh:Zh/Documentation/DevGuide/ProUNO/Singletons]]
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Singletons}}
 
{{DISPLAYTITLE:Singletons}}
 
Singletons are used to specify named objects where exactly ''one'' instance can exist in the life of a UNO component context. A singleton references one interface type and specifies that the only existing instance of this singleton can be reached over the component context using the name of the singleton. If no instance of the singleton exists, the component context will instantiate a new one. An example of such a ''new-style'' singleton is
 
Singletons are used to specify named objects where exactly ''one'' instance can exist in the life of a UNO component context. A singleton references one interface type and specifies that the only existing instance of this singleton can be reached over the component context using the name of the singleton. If no instance of the singleton exists, the component context will instantiate a new one. An example of such a ''new-style'' singleton is

Revision as of 07:57, 13 May 2009



Singletons are used to specify named objects where exactly one instance can exist in the life of a UNO component context. A singleton references one interface type and specifies that the only existing instance of this singleton can be reached over the component context using the name of the singleton. If no instance of the singleton exists, the component context will instantiate a new one. An example of such a new-style singleton is

  module com { module sun { module star { module deployment {
  singleton thePackageManagerFactory: XPackageManagerFactory;
  }; }; }; };

The various language bindings offer language-specific ways to obtain the instance of a new-style singleton, given a component context. For example, in Java and C++ there is a static method (resp. function) named get, that takes as its only argument an XComponentContext and returns the (appropriately typed) singleton instance. If the instance cannot be obtained, a com.sun.star.uno.DeploymentException is thrown.

There are also old-style singletons, which reference (old-style) services instead of interfaces. However, for old-style services, the language bindings offer no get functionality.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages