Re: Singletons / classes with only one member
W Karas wrote:
Suppose you have a class that has only one instance,
You mean, "only one data member"?
> and there is
little reason to think it would ever make sense for the class to have
more than one instance. What are some criteria for deciding whether
it should even be a class? [..]
Only make it a class if there is some *abstraction* you need to
represent in your program. For example (using your code), if you just
have an int somewhere, it's an int, and can be used anywhere the int can
be. If that int is wrapped in a class, the class instance (even if it's
only one per program) cannot be [easily] used where an int would go.
Another sentiment: it doesn't matter that your class has only one data
member. That's *implementation detail*, and it can change with time.
If you need a special type, have a special type. Don't design "from
bottom up", it's A BAD IDEA(tm). Design by describing your model. If
your model needs a class, have a class. How many data members it has is
of no consequence to the design itself.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask