Created
January 17, 2017 17:22
-
-
Save loderunner/4a659fba63100cd7c638ddf6da2f4c17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
public: | |
Foo(); | |
~Foo() {} | |
void platform_independent(); | |
void platform_specific(); | |
private: | |
FooImpl* _impl; | |
public: | |
static FooImpl* createImplementation(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Compile only in Mac project ***/ | |
#include "FooImplMac.h" | |
FooImpl* Foo::createImplementation() { | |
return new FooImplMac(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Compile only in Windows project ***/ | |
#include "FooImplWin.h" | |
FooImpl* Foo::createImplementation() { | |
return new FooImplWin(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Foo implementation abstract interface ***/ | |
class FooImplInterface { | |
public: | |
FooImplInterface() {} | |
virtual ~FooImplInterface() {} | |
virtual void do_platform_specific() = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FooImplWin.h" | |
FooImplWin::FooImplWin() | |
: FooImplInterface() | |
{ | |
} | |
FooImplWin::do_platform_specific() { | |
// Do some stuff the Windows way | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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