在工程实践中,一个大公司产品的实现需要各部门的互相协同,而产品的开发思路和设计用途(架构)需要架构师编写接口(Interface),C++的纯虚函数可以指定类中函数的形参类型,在开发者明确产品要实现的功能后,利用架构师所提供的形参(接口)实现功能。文章以华为电报接受为例
甲方端(华为本公司架构)
#pragma once
#include"iostream"
using namespace std;
class #pragma once
#include"iostream"
using namespace std;
class CSocketProtocal
{
public:
//客户端初始化,获取handle上下
virtual int cltSocketInit() = 0;
//客户端发报文
virtual int cltSocketSend(unsigned char* buf, int buflen) = 0;
//客户端收报文
virtual int cltSocketRev( unsigned char* buf, int* buflen) = 0;
//客户端释放资源
virtual int cltSocketDestory()=0;
};
#pragma once
class CEncDesProtocol
{
public:
CEncDesProtocol()
{
}
virtual ~CEncDesProtocol()
{
}
virtual int EncData(unsigned char* plai