C & C++ Programming - Factory Design Method
#ifndef OBJECT_WORKER
#define OBJECT_WORKER
#include "iostream"
using namespace std;
class CObjectWorker
{
public:
CObjectWorker();
~CObjectWorker();
void PrintCount();
};
#endif
#ifndef OBJECT_MANAGER
#define OBJECT_MANAGER
#include "ObjectWorker.h"
class CObjectManager
{
public:
CObjectManager();
~CObjectManager();
int ShowCount()
{
m_Count = 100;
return m_Count;
}
/*static void GetObjectManager()
{
cout << "In the Object manager\n";
}
static CObjectManager* GetObjectManager()
{
ObjManager = new CObjectManager();
return ObjManager;
}
*/
//static CObjectManager* ObjManager;
static void GetObjectManager()
{
cout << "Calling static function";
}
private:
int m_Count;
CObjectWorker* ObjWorker;
//CObjectManager ObjManager;
};
#endif
#include "stdafx.h"
#include "ObjectManager.h"
//CObjectManager::*ObjManager = NULL;
//CObjectManager::ObjManager = NULL;
CObjectManager::CObjectManager()
: m_Count(1)
{
cout << "Manager CTOR" << endl << m_Count << endl;
ObjWorker = new CObjectWorker;
}
CObjectManager::~CObjectManager()
{
cout << "Manager DTOR" << endl;
delete ObjWorker;
}
#include "stdafx.h"
#include "ObjectWorker.h"
#include "ObjectManager.h"
//class CObjectManager;
CObjectWorker::CObjectWorker()
{
cout << "Worker CTOR" << endl;
}
CObjectWorker::~CObjectWorker()
{
cout << "Worker DTOR" << endl;
}
void CObjectWorker::PrintCount()
{
cout << "In the Worker PrintCount" << endl;
//cout << CObjectManager::GetObjectManager()->ShowCount() << endl;
CObjectManager::GetObjectManager;
}
#include "stdafx.h"
#include "ObjectManager.h"
int _tmain(int argc, _TCHAR* argv[])
{
cout << "In the Main\n" ;
//cout << GetObjectManager()->ShowCount() << endl;
CObjectWorker obj;
obj.PrintCount();
return 0;
}