feature: add PImpl Pattern demo code.

master
FengJungle 2022-02-26 16:08:24 +08:00
parent 7235d125ef
commit 1d0bae0753
3 changed files with 49 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -0,0 +1,27 @@
#include "demo.h"
// include other necessary files
#include ....
class PAimpl
{
public:
void func1(int a, char* b)
{
// implementation
}
bool isEnabled()
{
// implementation
return true;
}
};
void A::func1(int a, char* b)
{
pimpl->func1(a, b);
}
bool A::isEnabled()
{
return pimpl->isEnabled();
}

View File

@ -0,0 +1,22 @@
/* header file */
// forward declaration
class PAimpl;
class A
{
public:
A()
{
// initial work
}
~A() {
// free resource
}
public:
void func1(int a, char* b);
bool isEnabled();
// other public interface which will exposed outside
private:
PAimpl* pimpl;
};