Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > singleton design

Reply
Thread Tools

singleton design

 
 
asit
Guest
Posts: n/a
 
      07-31-2011
I want to design a singleton class. here the rule is to make the constructor private. That's okey. What about copy constructor and assignment operator.. If I make it private, certain things like copying and assigning will leadto compiler error. How can I handle them ??
 
Reply With Quote
 
 
 
 
Dombo
Guest
Posts: n/a
 
      07-31-2011
Op 31-Jul-11 22:22, asit schreef:
> I want to design a singleton class. here the rule is to make the
> constructor private. That's okey. What about copy constructor
> and assignment operator. If I make it private, certain things
> like copying and assigning will lead to compiler error.
> How can I handle them ??


It wouldn't be really a singleton if you could copy it, nor would it
make sense to support assignment if only one can exist, would it?


 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      08-01-2011
asit <(E-Mail Removed)> writes:

> I want to design a singleton class.


Ick. Please reconsider.

There is usually no good reason to enforce that there is only one
instance of a class. Modelling-wise it might make sense to only
actually create one instance, but using the singleton (anti-)pattern
tends to bite you if you want to test either the class itself or
classes depending on it.

> here the rule is to make the constructor private. That's okey. What
> about copy constructor and assignment operator. If I make it
> private, certain things like copying and assigning will lead to
> compiler error. How can I handle them ??


If you want to only have one copy, you don't want to have assignment
or copying creating more than one instance. If the object is immutable,
it might not make any difference, but it still prevents it from being
a singleton.
You should only pass the object around by reference or pointer.

/L
--
Lasse Reichstein Holst Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Singleton methods without the singleton class Charles Oliver Nutter Ruby 4 03-22-2010 10:46 PM
Singleton object vs. enhancing singleton class Paul McMahon Ruby 3 06-09-2008 06:05 AM
Singleton Modules rather than Singleton Classes Trans Ruby 12 09-14-2007 06:45 AM
Singleton - Whether Cloneable overrides Singleton Proton Projects - Moin Java 4 03-27-2007 02:59 AM
Singleton classes and Singleton pattern Wilhelm Ruby 1 10-11-2006 01:08 PM



Advertisments