I'm writing an application which will run as a daemon. UIs will connect to it over TCP. Now, there is a class called UiTcpInterface which will handle all communication between the UI and this daemon.
Now, I'm faced with the problem of ensuring there is only one instance of UiTcpInterface. What would be the best way to do it? Currently, I've thought of two ways:
- This is the classic singleton pattern: make the constructor private, and provide a static
instance()method to the classUiTcpInterface - Implement all functionality as static members of
UiTcpInterface. The main method will make sure that all initialization is done.
Which of these two should I follow? Can you please give me a pro-con list of the two methods?
Thanks :)