Software Architecture--Singleton
Singleton is a pattern in Software Architecture. It is used to create a instance and there will be only one instance in system at any time. If you want to write this pattern in a file, it will be like that:
[codesyntax lang=“cpp” tab_width=“2”]
1 | #include <iostream> |
If you want write this pattern into different files, it will has Singleton.h Singleton.cpp and other files like that:
Singleton.h[codesyntax lang=“cpp” tab_width=“2”]
1 | /* ========================== |
Singleton.cpp
[codesyntax lang=“cpp” tab_width=“2”]
1 | #include "Singleton.h" |
main.cpp
[codesyntax lang=“cpp” tab_width=“2”]
1 | #include <iostream> |
But it dose not ensure this instance is only the same in the system. Because it will be destroyed and recreated.