Difference between revisions of "Documentation/DevGuide/WritingUNO/Singleton"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 9: Line 9:
 
{{DISPLAYTITLE:Singleton}}
 
{{DISPLAYTITLE:Singleton}}
 
A <code>singleton</code> declaration defines a global name for a UNO object and determines that there can only be one instance of this object that must be reachable under this name. The singleton instance can be retrieved from the component context using the name of the <code>singleton</code>. If the <code>singleton</code> has not been instantiated yet, the component context creates it. A ''new-style'' singleton declaration, that binds a singleton name to an object with a certain interface type, looks like this:
 
A <code>singleton</code> declaration defines a global name for a UNO object and determines that there can only be one instance of this object that must be reachable under this name. The singleton instance can be retrieved from the component context using the name of the <code>singleton</code>. If the <code>singleton</code> has not been instantiated yet, the component context creates it. A ''new-style'' singleton declaration, that binds a singleton name to an object with a certain interface type, looks like this:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   singleton thePackageManagerFactory:  
 
   singleton thePackageManagerFactory:  
 
   com::sun::star::depoyment::XPackageManager;
 
   com::sun::star::depoyment::XPackageManager;
</source>
+
</syntaxhighlight>
 
There are also ''old-style'' singletons, which reference (old-style) services instead of interfaces.
 
There are also ''old-style'' singletons, which reference (old-style) services instead of interfaces.
  

Latest revision as of 16:29, 23 December 2020



A singleton declaration defines a global name for a UNO object and determines that there can only be one instance of this object that must be reachable under this name. The singleton instance can be retrieved from the component context using the name of the singleton. If the singleton has not been instantiated yet, the component context creates it. A new-style singleton declaration, that binds a singleton name to an object with a certain interface type, looks like this:

  singleton thePackageManagerFactory: 
  com::sun::star::depoyment::XPackageManager;

There are also old-style singletons, which reference (old-style) services instead of interfaces.

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