In my library, I want to publish a pure public API that does not detract from implementation details. However, be that as it may, this data leaks even into the public sphere: some classes have valid public methods that are used by the rest of the library, but are not very useful for the API user and, t be part of this. A simplified example of open source:
class Cookie;
class CookieJar {
public:
Cookie getCookie();
}
class CookieMonster {
public:
void feed(CookieJar cookieJar) {
while (isHungry()) {
cookieJar.getCookie();
}
}
bool isHungry();
}
The method getCookie()for is CookieJarnot useful to the library user, who, apparently, does not like cookies in any case. However, it is used CookieMonsterto serve itself when assigned to it.
, . Pimpl , , API. , . :
class Cookie;
class CookieJarImpl;
class CookieJar {
public:
CookieJarImpl* getImplementation() {
return pimpl.get();
}
private:
std::unique_ptr<CookieJarImpl> pimpl;
}
, , , . , , CookieJarImpl.
. , API. , . , , , Pimpl. API , .
, - , . , , , .
Python: , , , , API . , , , , , , .
- ++ , - ? - , ?