English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

java,j2ee

2006-07-11 04:45:38 · 2 answers · asked by niranjan d 1 in Computers & Internet Software

2 answers

Singleton is probably the most widely used design pattern. Its intent is to ensure that a class has only one instance, and to provide a global point of access to it. There are many situations in which a singleton object is necessary: a GUI application must have a single mouse, an active modem needs one and only one telephone line, an operating system can only have one window manager, and a PC is connected to a single keyboard. I will show how to implement the singleton pattern in C++ and explain how you can optimize its design for single-threaded applications.

class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
Singleton(const Singleton&);
Singleton& operator= (const Singleton&);
private:
static Singleton* pinstance;
};

n so on n on

2006-07-11 23:36:35 · answer #1 · answered by Joe_Young 6 · 2 1

Get hold of a book on Design Patterns. for Java I would recommend the book below ( Head first Design Pattern)

2006-07-12 00:16:22 · answer #2 · answered by BikeNomad 2 · 0 0

fedest.com, questions and answers