diff --git a/AdapterPattern/AdapterPattern.cpp b/AdapterPattern/AdapterPattern.cpp new file mode 100644 index 0000000..901b2e7 --- /dev/null +++ b/AdapterPattern/AdapterPattern.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; + +class Target { +public: + virtual void Request() { + cout << "Target::Request..." << endl; + } + virtual ~Target() { } +}; + +class Adaptee { +public: + void SpecificRequest() { + cout << "Adaptee::SpecificRequest..." << endl; + } +}; + +class Adapter :public Target, private Adaptee { +public: + Adapter(Adaptee* ade) { + _ade = ade; + } + void Request() { + _ade->SpecificRequest(); + } +private: + Adaptee *_ade; +}; + +int main() { + Adaptee *adaptee = new Adaptee(); + Target *adapter = new Adapter(adaptee); + + adapter->Request(); + + delete adapter; + delete adaptee; + + return 0; +} diff --git a/AdapterPattern/AdapterPattern.vcxproj b/AdapterPattern/AdapterPattern.vcxproj new file mode 100644 index 0000000..f9daeca --- /dev/null +++ b/AdapterPattern/AdapterPattern.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {83BED35B-5633-4126-8AF3-EE46DFDB94DB} + Win32Proj + AdapterPattern + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/AdapterPattern/AdapterPattern.vcxproj.filters b/AdapterPattern/AdapterPattern.vcxproj.filters new file mode 100644 index 0000000..0bba511 --- /dev/null +++ b/AdapterPattern/AdapterPattern.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/BridgePattern/BridgePattern.cpp b/BridgePattern/BridgePattern.cpp new file mode 100644 index 0000000..da9c461 --- /dev/null +++ b/BridgePattern/BridgePattern.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; + +// Abstraction + +class Abstraction { +public: + virtual void Operation() = 0; + virtual ~Abstraction() { } +protected: + Abstraction() { } +}; + +// AbstractionImp + +class AbstractionImp :public Abstraction { +public: + virtual void Operation() = 0; + virtual ~AbstractionImp() { } +protected: + AbstractionImp() { } +}; + +class ConcreteAbstractionImp :public AbstractionImp { +public: + void Operation() { + cout << "ConcreteAbstractionImp Operation..." << endl; + } +}; + +class RefinedAbstraction :public Abstraction { +public: + RefinedAbstraction(AbstractionImp *imp) { + _imp = imp; + } + void Operation() { + _imp->Operation(); + } +private: + AbstractionImp *_imp; +}; + + + + + +int main() { + + AbstractionImp *imp = new ConcreteAbstractionImp(); + + Abstraction *abs = new RefinedAbstraction(imp); + + abs->Operation(); + + delete imp; + delete abs; + + return 0; +} diff --git a/BridgePattern/BridgePattern.vcxproj b/BridgePattern/BridgePattern.vcxproj new file mode 100644 index 0000000..ec7195b --- /dev/null +++ b/BridgePattern/BridgePattern.vcxproj @@ -0,0 +1,87 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {07800D56-D1F1-49D3-BD99-D4C6336F48AF} + Win32Proj + BridgePattern + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/BridgePattern/BridgePattern.vcxproj.filters b/BridgePattern/BridgePattern.vcxproj.filters new file mode 100644 index 0000000..37e1309 --- /dev/null +++ b/BridgePattern/BridgePattern.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + + + + \ No newline at end of file diff --git a/DesignPattern.sln b/DesignPattern.sln index 35a67eb..c754569 100644 --- a/DesignPattern.sln +++ b/DesignPattern.sln @@ -13,6 +13,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BuilderPattern", "BuilderPa EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrototypePattern", "PrototypePattern\PrototypePattern.vcxproj", "{6355F257-3305-4A22-9AA9-ADE08D7BC8D9}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BridgePattern", "BridgePattern\BridgePattern.vcxproj", "{07800D56-D1F1-49D3-BD99-D4C6336F48AF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdapterPattern", "AdapterPattern\AdapterPattern.vcxproj", "{83BED35B-5633-4126-8AF3-EE46DFDB94DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,6 +43,14 @@ Global {6355F257-3305-4A22-9AA9-ADE08D7BC8D9}.Debug|Win32.Build.0 = Debug|Win32 {6355F257-3305-4A22-9AA9-ADE08D7BC8D9}.Release|Win32.ActiveCfg = Release|Win32 {6355F257-3305-4A22-9AA9-ADE08D7BC8D9}.Release|Win32.Build.0 = Release|Win32 + {07800D56-D1F1-49D3-BD99-D4C6336F48AF}.Debug|Win32.ActiveCfg = Debug|Win32 + {07800D56-D1F1-49D3-BD99-D4C6336F48AF}.Debug|Win32.Build.0 = Debug|Win32 + {07800D56-D1F1-49D3-BD99-D4C6336F48AF}.Release|Win32.ActiveCfg = Release|Win32 + {07800D56-D1F1-49D3-BD99-D4C6336F48AF}.Release|Win32.Build.0 = Release|Win32 + {83BED35B-5633-4126-8AF3-EE46DFDB94DB}.Debug|Win32.ActiveCfg = Debug|Win32 + {83BED35B-5633-4126-8AF3-EE46DFDB94DB}.Debug|Win32.Build.0 = Debug|Win32 + {83BED35B-5633-4126-8AF3-EE46DFDB94DB}.Release|Win32.ActiveCfg = Release|Win32 + {83BED35B-5633-4126-8AF3-EE46DFDB94DB}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesignPattern.v12.suo b/DesignPattern.v12.suo index 68e485a..101aa7d 100644 Binary files a/DesignPattern.v12.suo and b/DesignPattern.v12.suo differ