-1

I new to this platform and I would like to create a singleton class in Tizen. As Tizen has two files .h and .m , am little confused that how to create a Singleton class. Can anyone tell me how to create?

user2431170
  • 151
  • 2
  • 11
  • 5
    Please do not do this. –  Aug 12 '13 at 10:10
  • Read http://stackoverflow.com/questions/2496918/singleton-pattern-in-c. It is at least comprehensive. – user2672165 Aug 12 '13 at 10:15
  • @user2431170 : Nowadays it is generally considered as an absolute truth that you should never use singletons no matter what. – user2672165 Aug 12 '13 at 11:29
  • @user2672165. Is there any other design pattern I could use throughout the life cycle of the application ? – user2431170 Aug 12 '13 at 12:52
  • @user2672165: http://stackoverflow.com/questions/7267061/alternatives-to-singletons. Between you and me: I am not sure it is an absolute truth beacuse I am not capable of imagining all possible situations that can occur. – user2672165 Aug 12 '13 at 13:02
  • 1
    _"As Tizen has two files .h and .m"_. Huh? Do you mean .h and .cpp? In any case, I don't see how the implementation would differ compared to how you'd do it on another platform. – Michael Aug 12 '13 at 13:59

2 Answers2

2

you have to declare methods in .h file and define them in .cpp this code is in one file but i think writing in two files, shouldn't cause you problems

 class singleton
 {
  private:
        singleton() {}
        singleton(const singleton &);
        singleton& operator=(const singleton&);
        ~singleton() {}
  public:
        std::string method() { return "singleton pattern"; }
        static singleton& getInstance()
        {
          static singleton instance;
          return instance;
        }
 };

 //Using
 std::cout << singleton::getInstance().method();
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
xyra
  • 21
  • 2
1

Tizen supports Standard C++ ANSI ISO 14882 2003. So there's nothing specific in Tizen concerning algorithms, programming technics, design patterns etc. And in Tizen standard source (.cpp) and header (.h) files are used.

Amarantine
  • 106
  • 2