Bug 177523 - [api][breaking] Unify method names for getting Singleton instances
Summary: [api][breaking] Unify method names for getting Singleton instances
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 1.0.1   Edit
Hardware: All All
: P2 enhancement (vote)
Target Milestone: 2.0   Edit
Assignee: Martin Oberhuber CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: api
: 185097 (view as bug list)
Depends on:
Blocks: 221488
  Show dependency tree
 
Reported: 2007-03-15 06:23 EDT by Martin Oberhuber CLA
Modified: 2008-08-13 13:18 EDT (History)
1 user (show)

See Also:


Attachments
Refactoring Script for renamings (12.67 KB, text/plain)
2007-05-10 08:50 EDT, Martin Oberhuber CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Oberhuber CLA 2007-03-15 06:23:37 EDT
In RSE, there are several different patterns of method names for getting singleton instances. I find these by doing a text search for "public static" in all java files and filtering to only show matches which include "()".
For instance:

SystemRegistry.getSystemRegistry()
SystemProfileManager.getSystemProfileManager()
DStoreConnectorServiceManager.getTheUniversalSystemManager()
DaytimeConnectorServiceManager.getTheDaytimeConnectorServiceManager()
SshConnectorServiceManager.getInstance()
ArchiveHandlerManager.getInstance()
FTPConnectorServiceManager.getDefault()

I find these different patterns for accessing singleton instances very confusing. Before M6, we still have the chance to fix this and come up with a more common naming scheme. I personally like the getInstance() name best:

SystemRegistry.getInstance()
SystemProfileManager.getInstance()
DStoreConnectorServiceManager.getInstance()
DaytimeConnectorServiceManager.getInstance()

Please comment on this request.
Comment 1 Javier Montalvo Orús CLA 2007-03-15 07:14:08 EDT
Sounds good to me.

+1
Comment 2 David Dykstal CLA 2007-03-15 07:59:50 EDT
I like getInstance() as well. The plugin classes themselves tend to use getDefault(), which I think we should keep for that particular case - otherwise getInstance() should be the one.
Comment 3 Uwe Stieber CLA 2007-03-15 08:08:58 EDT
+ 1

I would like to see to go even a step further an would eliminate access methods
in plugins and managers which only forward to an singleton instance getter
method and access methods which forward to another plugin which forwards again
to singleton instance getter method.

Like: 

RSEUIPlugin.getThePersistenceManager() ->
RSECorePlugin.getThePersistenceManager() -> getDefault().getPeristenceManager()

- all of these calls could be just RSEPersistenceManager.getInstance()

Or:

SystemStartHere.getSystemProfileManager() ->
SystemProfileManager.getSystemProfileManager()

- There is no need for methods like SystemStartHere.getSystemProfileManager().
Singleton instance should be accessed via <SingletonClass>.getInstance()
directly.
Comment 4 David McKnight CLA 2007-03-15 08:14:39 EDT
I agree, getInstance() is a far more standard, readable and predictable approach.

+1
Comment 5 Lothar Werzinger CLA 2007-03-15 11:12:02 EDT
I'm not a committer, but I think it's a good idea. Everything that makes the use of RSE easier for the user is worth a change.

+1
Comment 6 Kushal Munir CLA 2007-03-15 15:09:57 EDT
getInstance() is pretty common and also agree with Uwe's comments: +1
Comment 7 Martin Oberhuber CLA 2007-05-10 08:47:59 EDT
(In reply to comment #3)
> I would like to see to go even a step further an would eliminate access
> methods in plugins and managers which only forward to an singleton instance
> getter method

This cannot be done since many singletons belong to "internal" implementation, so they need public API access methods returning the corresponding interfaces. 
Examples for these are 
  RSECorePlugin.getTheSystemRegistry()
  RSECorePlugin.getTheCoreRegistry()

I'd like to keep the *.getThe*() naming scheme for these, in order to indicate that singletons are being returned. This may not be 100% Eclipse Standard, but it's a small deviation and I like it.
Comment 8 Martin Oberhuber CLA 2007-05-10 08:50:03 EDT
Created attachment 66655 [details]
Refactoring Script for renamings

Work completed, checkin comment: 
[177523][api] Unify singleton getter methods to use getInstance()

In order to apply the changes to a local workspace, just choose
Refactor > Apply Script... in Eclipse, and load attached
refactoring script.

Regular Expressions used for searching access methods:
getThe
getDefault
getSingleton
public\s+static\s+(\w*)\s+.*\1.*\(\)

API Changes:
------------
DStoreConnectorServiceManager.getInstance()
    -- [was: getTheUniversalSystemManager()]
RSECorePlugin.getTheCoreRegistry() -- [new]
RSECorePlugin.getTheSystemRegistry() -- [new]
RSECorePlugin.getThePersistenceManager() -- [moved from: RSEUIPlugin]
RSEUIPlugin.getThePersistenceManager() -- [removed]
SystemFileTransferModeRegistry.getInstance() -- [was: getDefault()]

Non-API Changes:
----------------
DaytimeConnectorServiceManager.getInstance()
   -- [was: getTheDaytimeConnectorServiceManager()]
DeveloperConnectorServiceManager.getInstance()
   -- [was: getTheDeveloperConnectorServiceManager()]
FTPConnectorServiceManager.getInstance() -- [was: getDefault()]
LocalConnectorServiceManager.getInstance() -- [was: getTheLocalSystemManager()]
ServiceDiscoveryEngine.getInstance() -- [was: getServiceDiscoveryEngine()]
SystemFilterStartHere.getInstance() -- [was: getDefault()]
SystemRemoteEditManager.getInstance() -- [was: getDefault()]
SystemUDASubstVarListCommon.getInstance() -- [was: getSingleton()]
SystemViewDummyObject.getInstance() -- [was: getSingleton()]
UDSubstListFolders.getInstance() -- [was: getSingleton()]
UDSubstListCommonFiles.getInstance() -- [was: getSingleton()]
UDSubstListFiles.getInstance() -- [was: getSingleton()]
UniversalCompileSubstList.getInstance() -- [was: getSingleton()]

Access methods not changed:
---------------------------------
RSEUIPlugin.getTheSystemProfileManager() -- TBD separately when moving to Core
RSEUIPlugin.getTheSystemRegistry() -- returns SystemRegistryUI
SystemProfileManager.getDefault() -- remains since not really a singleton
Comment 9 Martin Oberhuber CLA 2007-05-10 08:51:13 EDT
Work completed. See the migration docs in comment #8 and the refactoring script, which you can apply to a local workspace, in attachment #66655 [details].
Comment 10 Martin Oberhuber CLA 2007-05-10 12:56:25 EDT
*** Bug 185097 has been marked as a duplicate of this bug. ***
Comment 11 Martin Oberhuber CLA 2008-08-13 13:18:27 EDT
[target cleanup] 2.0 M7 was the original target milestone for this bug