Definition:
A class whose number of instances that can be
instantiated is limited to one is called a singleton class. Thus, at any given
time only one instance can exist, no more.
Can
you give me an example, where it is
used?
The singleton design
pattern is used whenever the design requires only one instance of a class. Some
examples:
- Application classes. There should only be one application class. (Note: Please bear in mind, MFC class 'CWinApp' is not implemented as a singleton class)
- Logger classes. For logging purposes of an application there is usually one logger instance required.
No comments:
Post a Comment