KnightOnHorse的博客

追求技术的道路永无止境

项目经理,一个Java程序员和一个C++程序员

//声明文件

class CUserInterfaceLayer{//界面层
private:
	string strLayer;
public:
	void SetLayer(string language);
	string GetLayer();
};
class CBusinessLogicLayer{//业务逻辑层
private:
	string strLayer;
public:
	void SetLayer(string language);
	string GetLayer();
};
class CDataAccessLayer{//数据访问曾
private:
	string strLayer;
public:
	void SetLayer(string language);
	string GetLayer();
};
class CAppDevelop{//抽象的开发人员
public:
	virtual void BuildUIL() = 0;
	virtual void BuildBLL() = 0;
	virtual void BuildDAL() = 0;
	virtual void FinishTask() = 0;
};
class CCPlusPlusProgrammer : public CAppDevelop{//MFC C++ ODBC(C++相关技术)
private:
	CUserInterfaceLayer* pUIL;
	CBusinessLogicLayer* pBLL;
	CDataAccessLayer* pDAL;
public:
	CCPlusPlusProgrammer();
	~CCPlusPlusProgrammer();
	void BuildUIL();
	void BuildBLL();
	void BuildDAL();
	void FinishTask();
};
class CJavaProgrammer : public CAppDevelop{//Swing Java JDBC(Java相关技术)
private:
	CUserInterfaceLayer* pUIL;
	CBusinessLogicLayer* pBLL;
	CDataAccessLayer* pDAL;
public:
	CJavaProgrammer();
	~CJavaProgrammer();
	void BuildUIL();
	void BuildBLL();
	void BuildDAL();
	void FinishTask();
};
class CProMgr{
private:
	CAppDevelop* pProgrammer;
public:
	void SelectProgrammer(CAppDevelop* programmer);
	void Consturct();
};

//实现文件

void CUserInterfaceLayer::SetLayer(string language){ strLayer = language + " UserInterface.";}
string CUserInterfaceLayer::GetLayer(){ return strLayer;}

void CBusinessLogicLayer::SetLayer(string language){ strLayer = language + " BusinessLogic.";}
string CBusinessLogicLayer::GetLayer(){return strLayer;}

void CDataAccessLayer::SetLayer(string language){strLayer = language + " DataAccess.";}
string CDataAccessLayer::GetLayer(){return strLayer;}


CCPlusPlusProgrammer::CCPlusPlusProgrammer()
{
	pUIL = new CUserInterfaceLayer();
	pBLL = new CBusinessLogicLayer();
	pDAL = new CDataAccessLayer();
}
CCPlusPlusProgrammer::~CCPlusPlusProgrammer()
{
	if(pUIL != NULL)				delete pUIL;
	if(pBLL != NULL)			delete pBLL;
	if(pDAL != NULL)			delete pDAL;
}
void CCPlusPlusProgrammer::BuildUIL(){pUIL->SetLayer("MFC");}
void CCPlusPlusProgrammer::BuildBLL(){pBLL->SetLayer("C++");}
void CCPlusPlusProgrammer::BuildDAL(){pDAL->SetLayer("ODBC");}
void CCPlusPlusProgrammer::FinishTask()
{
	cout << "*********************" << endl;
	cout << "Exe including" << endl;
	cout << pUIL->GetLayer() << endl;
	cout << pBLL->GetLayer() << endl;
	cout << pDAL->GetLayer() << endl;
	cout << "*********************" << endl;
}

CJavaProgrammer::CJavaProgrammer()
{
	pUIL = new CUserInterfaceLayer();
	pBLL = new CBusinessLogicLayer();
	pDAL = new CDataAccessLayer();
}
CJavaProgrammer::~CJavaProgrammer()
{
	if(pUIL != NULL)				delete pUIL;
	if(pBLL != NULL)			delete pBLL;
	if(pDAL != NULL)			delete pDAL;
}
void CJavaProgrammer::BuildUIL(){pUIL->SetLayer("Swing");}
void CJavaProgrammer::BuildBLL(){pBLL->SetLayer("Java");}
void CJavaProgrammer::BuildDAL(){pDAL->SetLayer("JDBC");}
void CJavaProgrammer::FinishTask()
{
	cout << "*********************" << endl;
	cout << "Jar including" << endl;
	cout << pUIL->GetLayer() << endl;
	cout << pBLL->GetLayer() << endl;
	cout << pDAL->GetLayer() << endl;
	cout << "*********************" << endl;
}


void CProMgr::SelectProgrammer(CAppDevelop* programmer){pProgrammer = programmer;}
void CProMgr::Consturct()
{
	pProgrammer->BuildUIL();
	pProgrammer->BuildBLL();
	pProgrammer->BuildDAL();
}

//测试客户端

void main()
{
	CProMgr oProMgr;//项目经理
	CJavaProgrammer oJava;//Java程序猿
	CCPlusPlusProgrammer oCPlusPlus;//C++程序猿

	oProMgr.SelectProgrammer(&oJava);
	oProMgr.Consturct();
	oJava.FinishTask();

	oProMgr.SelectProgrammer(&oCPlusPlus);
	oProMgr.Consturct();
	oCPlusPlus.FinishTask();
}

阅读更多
版权声明:本文为博主原创文章,允许转载,转载请注明出处。 https://blog.csdn.net/KnightOnHourse/article/details/79973999
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

项目经理,一个Java程序员和一个C++程序员

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭