Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too Many Singletons (intention to drop) #4

Open
David-Estevez opened this issue Oct 24, 2014 · 1 comment
Open

Too Many Singletons (intention to drop) #4

David-Estevez opened this issue Oct 24, 2014 · 1 comment

Comments

@David-Estevez
Copy link
Collaborator

Currently there is controversy between developers about if there is an abuse of the Singleton pattern used in Robot Devastation.

This may serve as a discussion thread to try to arrive to an agreement.

@jgvictores jgvictores changed the title Too Many Singletons ? Too Many Singletons Feb 9, 2015
@jgvictores jgvictores changed the title Too Many Singletons Too Many Singletons (intention to drop) Feb 9, 2015
PeterBowman added a commit that referenced this issue Apr 16, 2017
One could still create copies with the following code:

// Create singleton
MockImageManager::RegisterManager();
ImageManager * im = ImageManager::getImageManager(MockImageManager::id);

// Violate singleton's contract with copy constructor
MockImageManager * temp = (MockImageManager*)im; // for conciseness
MockImageManager mim1(*temp);                         // copy-ctor #1
MockImageManager mim2 = *temp;                        // copy-ctor #2
MockImageManager mim3 = MockImageManager(*temp);      // copy-ctor #3
MockImageManager *pmim = new MockImageManager(*temp); // copy-ctor #4

// Copy assignment operator
mim1 = mim3;

See also http://stackoverflow.com/a/6811055
@PeterBowman
Copy link
Member

PeterBowman commented May 18, 2018

Not actually speaking about singleton removal here, but the mechanism could be simplified by using local static variables instead of unique pointers, see robotology/yarp#1685.

Edit: perhaps the relevant changes are easier to spot in robotology/yarp@51d9cec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants