Skip to content

Instantly share code, notes, and snippets.

@loderunner
Created January 17, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loderunner/4a659fba63100cd7c638ddf6da2f4c17 to your computer and use it in GitHub Desktop.
Save loderunner/4a659fba63100cd7c638ddf6da2f4c17 to your computer and use it in GitHub Desktop.
Foo::Foo()
: _impl(Foo::createImplementation())
{
}
void Foo::platform_independent() {
// do some stuff that is the same on all platforms
}
void Foo::platform_specific() {
_impl->do_platform_specific();
}
class Foo {
public:
Foo();
~Foo() {}
void platform_independent();
void platform_specific();
private:
FooImpl* _impl;
public:
static FooImpl* createImplementation();
};
/*** Compile only in Mac project ***/
#include "FooImplMac.h"
FooImpl* Foo::createImplementation() {
return new FooImplMac();
}
/*** Compile only in Windows project ***/
#include "FooImplWin.h"
FooImpl* Foo::createImplementation() {
return new FooImplWin();
}
/*** Foo implementation abstract interface ***/
class FooImplInterface {
public:
FooImplInterface() {}
virtual ~FooImplInterface() {}
virtual void do_platform_specific() = 0;
}
#include "FooImplWin.h"
FooImplWin::FooImplWin()
: FooImplInterface()
{
}
FooImplWin::do_platform_specific() {
// Do some stuff the Windows way
}
#include "FooImpl.h"
class FooImplWin : public FooImpl {
public:
FooImplWin();
virtual ~FooImplWin() {}
virtual void do_platform_specific();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment