64,682
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class DBUtill
{
public:
virtual void getConnection()
{
cout<<"basic getConnection()"<<endl;
}
};
class OracleDBUtill : public DBUtill
{
public:
virtual void getConnection()
{
cout<<"sub getConnection()"<<endl;
}
};
class CustomerDAO
{
private:
DBUtill utill;
public:
CustomerDAO(DBUtill utill)
{
this->utill = utill;
}
~CustomerDAO()
{
}
void addCustomer()
{
utill.getConnection();
}
};
int main()
{
DBUtill d1;
OracleDBUtill od1;
CustomerDAO* c1 = new CustomerDAO(d1);
CustomerDAO* c2 = new CustomerDAO(od1);
c1->addCustomer();
c2->addCustomer();
return 0;
}
#include<iostream>
using namespace std;
class DBUtill
{
public:
virtual void getConnection()
{
cout<<"basic getConnection()"<<endl;
}
};
class OracleDBUtill : public DBUtill
{
public:
virtual void getConnection()
{
cout<<"sub getConnection()"<<endl;
}
};
class CustomerDAO
{
private:
DBUtill* utill;
public:
CustomerDAO(DBUtill* utill)
{
this->utill = utill;
}
~CustomerDAO()
{
}
void addCustomer()
{
utill->getConnection();
}
};
int main()
{
DBUtill* d1= new DBUtill();
OracleDBUtill* od1 = new OracleDBUtill();
CustomerDAO* c1 = new CustomerDAO(d1);
CustomerDAO* c2 = new CustomerDAO(od1);
c1->addCustomer();
c2->addCustomer();
return 0;
}