{"id":5658,"date":"2022-01-24T18:13:23","date_gmt":"2022-01-24T10:13:23","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=5658"},"modified":"2022-01-24T18:13:23","modified_gmt":"2022-01-24T10:13:23","slug":"design-patterns-in-modern-c-%e4%b8%ad%e6%96%87%e7%89%88%e7%bf%bb%e8%af%91","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5658","title":{"rendered":"Design Patterns In Modern C++ \u4e2d\u6587\u7248\u7ffb\u8bd1"},"content":{"rendered":"<p dir=\"auto\"><a href=\"https:\/\/github.com\/liuzengh\/design-pattern\">\u539f\u6587\u5730\u5740<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3 dir=\"auto\"><a id=\"user-content-\u52a8\u673a\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%8A%A8%E6%9C%BA\" aria-hidden=\"true\"><\/a>\u52a8\u673a<\/h3>\n<ol dir=\"auto\">\n<li>\u672c\u4e66\u7684\u793a\u4f8b\u662f\u7528C++11\u300114\u300117\u548c\u66f4\u9ad8\u7248\u672c\u7684\u73b0\u4ee3C++\u7f16\u5199\u7684\uff0c\u6709\u52a9\u4e8e\u719f\u6089\u73b0\u4ee3C++\u7684\u8bed\u6cd5\u3002<\/li>\n<li>\u8bbe\u8ba1\u6a21\u5f0f\u662f\u7f16\u7a0b\u7ecf\u9a8c\u7684\u603b\u7ed3\uff0c\u5e7f\u6cdb\u5b58\u5728\u4e8e\u5de5\u7a0b\u5b9e\u8df5\u4e2d\uff0c\u7275\u626f\u51fa\u975e\u5e38\u591a\u7684\u76f8\u5173\u5185\u5bb9\uff08\u6bd4\u5927\u5bb6\u719f\u6089\u7684\u5355\u4f8b\u6a21\u5f0f\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u5f15\u51faC++11\u540e\u7684\u591a\u7ebf\u7a0b\u5185\u5b58\u6a21\u578b\uff0c\u9664\u4e86\u7528\u5c40\u90e8\u9759\u6001\u53d8\u91cf\u8fd8\u53ef\u4ee5\u7528Acquire and Release\u6805\u680f\uff0c Sequentially Consistent \u539f\u5b50\u64cd\u4f5c\u7b49\u65e0\u9501\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4ee5\u53cafolly\u4e2d\u5982\u4f55\u5728\u5de5\u4e1a\u5b9e\u8df5\u4e2d\u5b9e\u73b0Singleton\u6765\u7ba1\u7406\u591a\u4e2aSingletons\uff09\uff0c\u4ee5\u6b64\u4e3a\u7ebf\u7d22\u68b3\u7406\u6240\u5b66\u7684\u77e5\u8bc6\u3002<\/li>\n<li>\u6253\u7b97\u5728\u539f\u4e66\u7684\u57fa\u7840\u4e0a\u8865\u5145\u5927\u91cf\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5982STL\u3001Boost\u548cfolly\u4e2d\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u4e3e\u4f8bLeetcode\u9898\u76ee\u4e2d\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u8fd8\u6709\u878d\u5165\u591a\u7ebf\u7a0b\u5e76\u53d1\u60c5\u51b5\u4e0b\u7684\u4e00\u4e9b\u4f8b\u5b50\u3002<\/li>\n<\/ol>\n<h3 dir=\"auto\"><a id=\"user-content-todo\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#todo\" aria-hidden=\"true\"><\/a>TODO<\/h3>\n<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter01: Introduction. \u6211\u76f4\u63a5\u4f7f\u7528\u4e86<a href=\"https:\/\/github.com\/soyoo\/design_patterns_in_modern_cpp_zh_sample\">@soyoo\u7684\u7ffb\u8bd1\u7ed3\u679c<\/a><\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter02: Builder\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter03: Factories. \u6d89\u53ca\u5de5\u5382\u65b9\u6cd5\u3001\u5de5\u5382\u3001\u5185\u90e8\u5de5\u5382\u3001\u62bd\u8c61\u5de5\u5382\u548c\u51fd\u6570\u5de5\u5382\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter04: Prototype. \u539f\u578b\u6a21\u5f0f\uff0c\u5bf9\u6df1\u62f7\u8d1d\u7684\u5b9e\u73b0\u505a\u4e86\u4e00\u4e9b\u8ba8\u8bba(\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u548c\u62f7\u8d1d\u590d\u5236\u8fd0\u7b97\u7b26\uff1b\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316)\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter05: Singleton. \u7ebf\u7a0b\u5b89\u5168\uff0c\u5355\u4f8b\u7684\u95ee\u9898\uff0c\u63a7\u5236\u53cd\u8f6c\u548cMonostate.<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter06: Adapter. \u989d\u5916\u8865\u5145\u4e86STL\u4e2dqueue\u7684\u5b9e\u73b0\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u5b89\u5168\u548c\u65b9\u6cd5\u7684Queue\u3002\u9700\u8981\u4e86\u89e3boost\u5e93\u4e2d\u7684hash\u662f\u600e\u4e48\u505a\u7684\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter07: Bridge. \u589e\u52a0\u4e86Pimpl\u7f16\u7a0b\u6280\u6cd5\u7684\u8bf4\u660e\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter08: Composite.<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter09\uff1aDecorator. \u6d89\u53ca\u52a8\u6001\u88c5\u9970\u5668\u3001\u9759\u6001\u88c5\u9970\u5668 \u548c \u51fd\u6570\u88c5\u9970\u5668\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter10: Facade. \u5916\u89c2\u6a21\u5f0f, \u7f13\u51b2-\u89c6\u7a97-\u63a7\u5236\u53f0\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter11: Flyweight. \u4eab\u5143\u6a21\u5f0f\u3002Boost\u5e93\u4e2dFlyweight\u7684\u5b9e\u73b0\uff0c\u4ee5\u53caBimap<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter12: Proxy. \u667a\u80fd\u6307\u9488\u3001\u5c5e\u6027\u4ee3\u7406\u3001\u865a\u4ee3\u7406\u548c\u901a\u4fe1\u4ee3\u7406\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter13: Chain of Responsibility. \u6307\u9488\u94fe\uff1b\u4ee3\u7406\u94fe\u6d89\u53ca\u4e2d\u4ecb\u6a21\u5f0f\u548c\u89c2\u5bdf\u8005\u6a21\u5f0f\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter14: Command.<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter15: Interpreter.\u6d89\u53ca\u7f16\u8bd1\u539f\u7406\u91cc\u9762\u7684\u8bcd\u6cd5\u5206\u6790\uff0c\u8bed\u6cd5\u5206\u6790\uff0c<code>Boost.spirit<\/code>\u7684\u4f7f\u7528\u3002\u540e\u9762\u4f1a\u8865\u5145LeetCode\u4e0a\u5b9e\u73b0\u8ba1\u7b97\u5668\u7684\u51e0\u9053\u9898\u76ee\u548c\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u9898\u76ee\uff0c\u4e5f\u8bb8\u4f1a\u589e\u52a0<code>Lex\/Yacc<\/code>\u5de5\u5177\u7684\u4f7f\u7528\u4ecb\u7ecd\uff0c\u4ee5\u53catinySQL\u89e3\u91ca\u5668\u5b9e\u73b0\u7684\u7b80\u5355\u89e3\u91ca\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter16: Iterator. STL\u5e93\u4e2d\u7684\u8fed\u4ee3\u5668\uff0c\u6d89\u53ca\u4e8c\u53c9\u6811\u7684\u8fed\u4ee3\u5668\uff0c\u4f7f\u7528\u534f\u7a0b\u6765\u7b80\u5316\u8fed\u4ee3\u8fc7\u7a0b\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter17: Mediator.<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter18: Memento.<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter19: Nulll Object. \u6d89\u53ca\u5230\u5bf9\u4ee3\u7406\u6a21\u5f0f\u548cpimpl\u7f16\u7a0b\u6280\u6cd5\u7684\u8fd0\u7528\uff0c\u4ee5\u53castd::optional<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter20: Observer. \u5c5e\u6027\u89c2\u5bdf\u8005\u3001\u6a21\u677f\u89c2\u5bdf\u8005Observer&lt;T&gt;\u3001\u53ef\u89c2\u5bdfObservable&lt;T&gt; \u3001\u4f9d\u8d56\u95ee\u9898, \u53d6\u6d88\u8ba2\u9605\u4e0e\u7ebf\u7a0b\u5b89\u5168 \u548c\u4f7f\u7528Boost.Signals2 \u6765\u5b9e\u73b0 Observer\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter21: State. \u8865\u5145\u5b57\u7b26\u4e32\u5339\u914d\u3001\u4f8b\u5b50<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter22: Strategy. \u52a8\u6001\u7b56\u7565\u548c\u9759\u6001\u7b56\u7565<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter23: Template Method. \u6a21\u7248\u65b9\u6cd5\u6a21\u5f0f\u548c\u7b56\u7565\u6a21\u5f0f\u7684\u5f02\u540c\u3002<\/li>\n<li class=\"task-list-item\"><input id=\"\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" type=\"checkbox\" \/>\u00a0Chapter24: Visitor. \u5165\u4fb5\u5f0f\u3001\u53cd\u5c04\u5f0f\u3001\u7ecf\u5178\u5f0f\u7684\u8bbf\u95ee\u8005\u7684\u8bbe\u8ba1\u601d\u8def\uff0cstd::visitor\u5728variant\u7c7b\u578b\u4e0a\u7684\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\"><a id=\"user-content-\u8865\u5145\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%A1%A5%E5%85%85\" aria-hidden=\"true\"><\/a>\u8865\u5145<\/h2>\n<p dir=\"auto\">\u5728\u539f\u8457\u7684\u57fa\u7840\u4e0a\u8865\u5145\u4e86\u5f88\u591a\u76f8\u5173\u7684\u4e1c\u897f\uff0c<\/p>\n<ul dir=\"auto\">\n<li>\u7b2c5\u7ae0-\u5355\u4f8b\uff1a\u8865\u5145\u4e86\u65e0\u9501\u7684double-check\u5b9e\u73b0\u3002<\/li>\n<li>\u7b2c6\u7ae0-\u9002\u914d\u5668\uff1a\u63a2\u8ba8\u4e86STL\u4e2dqueue\u7684\u9002\u914d\u5668\u8bbe\u8ba1\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u65b9\u4fbf\u548c\u66f4\u5b89\u5168\u7684<code>Queue<\/code>\u9002\u914d\u5668\u5b9e\u73b0\u3002<\/li>\n<li>\u7b2c7\u7ae0-\u6865\u63a5\uff1a\u5bf9C++\u4e2d\u7684Pimpl\u7f16\u7a0b\u6280\u6cd5\u8fdb\u884c\u4e86\u8865\u5145\uff0c\u7ed9\u51fa\u4e86\u5728\u7f16\u8bd1\u5668\u65b9\u9762\u7684\u5e94\u7528\u3002<\/li>\n<li>\u7b2c12\u7ae0-\u4ee3\u7406\uff1a\u8ba8\u8bbaC++\u4e2d\u667a\u80fd\u6307\u9488\u7684\u5b9e\u73b0\uff0c\u7ed9\u51fa\u4e00\u4e2a\u534a\u7ebf\u7a0b\u5b89\u5168\u7684\u667a\u80fd\u6307\u9488<code>shared_ptr<\/code>\u7684\u5b9e\u73b0\u3002<\/li>\n<li>\u7b2c20\u7ae0-\u89c2\u5bdf\u8005\uff1a\u8865\u5145\u4e86\u7531\u89c2\u5bdf\u8005\u6a21\u5f0f\u884d\u751f\u51fa\u6765\u7684\u53d1\u5e03-\u8ba2\u9605\u6a21\u5f0f\uff0c\u603b\u7ed3\u4e86\u6d88\u606f\u961f\u5217\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879\uff0c\u63d0\u4f9b\u4e862\u79cd\u7528redis\u6765\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\"><a id=\"user-content-\u7b2c5\u7ae0-\u5355\u4f8b\u65e0\u9501\u7684double-check\u5b9e\u73b0\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%AC%AC5%E7%AB%A0-%E5%8D%95%E4%BE%8B%E6%97%A0%E9%94%81%E7%9A%84double-check%E5%AE%9E%E7%8E%B0\" aria-hidden=\"true\"><\/a>\u7b2c5\u7ae0-\u5355\u4f8b\uff1a\u65e0\u9501\u7684double-check\u5b9e\u73b0<\/h3>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre><span class=\"pl-k\">class<\/span> <span class=\"pl-en\">Singleton<\/span>\r\n{\r\n    <span class=\"pl-k\">protected:<\/span>\r\n        <span class=\"pl-en\">Singleton<\/span>();\r\n    <span class=\"pl-k\">private:<\/span>\r\n        <span class=\"pl-k\">static<\/span> std::mutex m_mutex;\r\n        <span class=\"pl-k\">static<\/span> std::atomic&lt;Singleton*&gt; m_instance = <span class=\"pl-c1\">nullptr<\/span>;\r\n    <span class=\"pl-k\">public:<\/span>\r\n        <span class=\"pl-k\">static<\/span> Singleton* <span class=\"pl-en\">Singleton::getInstance<\/span>() \r\n        {\r\n            Singleton* tmp = m_instance.<span class=\"pl-c1\">load<\/span>(std::memory_order_acquire);\r\n            <span class=\"pl-k\">if<\/span> (tmp == <span class=\"pl-c1\">nullptr<\/span>) \r\n            {\r\n                <span class=\"pl-c\">\/\/std::scoped_lock(m_mutex);<\/span>\r\n                std::lock_guard&lt;std::mutex&gt; <span class=\"pl-c1\">lock<\/span>(m_mutex);\r\n                tmp = m_instance.<span class=\"pl-c1\">load<\/span>(std::memory_order_relaxed);\r\n                <span class=\"pl-k\">if<\/span> (tmp == <span class=\"pl-c1\">nullptr<\/span>) \r\n                {\r\n                    tmp = <span class=\"pl-k\">new<\/span> Singleton;\r\n                    m_instance.<span class=\"pl-c1\">store<\/span>(tmp, std::memory_order_release);\r\n                }\r\n            }\r\n            <span class=\"pl-k\">return<\/span> tmp;\r\n        }\r\n        <span class=\"pl-en\">Singleton<\/span>(<span class=\"pl-k\">const<\/span> Singleton&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n        Singleton&amp; <span class=\"pl-k\">operator<\/span>=(<span class=\"pl-k\">const<\/span> Singleton&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n        <span class=\"pl-en\">Singleton<\/span>(Singleton&amp;&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n        Singleton&amp; <span class=\"pl-k\">operator<\/span>=(Singleton&amp;&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n\r\n};<\/pre>\n<\/div>\n<h3 dir=\"auto\"><a id=\"user-content-\u7b2c6\u7ae0-\u9002\u914d\u5668\u8bbe\u8ba1\u66f4\u5b89\u5168\u65b9\u4fbf\u7684queue\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%AC%AC6%E7%AB%A0-%E9%80%82%E9%85%8D%E5%99%A8%E8%AE%BE%E8%AE%A1%E6%9B%B4%E5%AE%89%E5%85%A8%E6%96%B9%E4%BE%BF%E7%9A%84queue\" aria-hidden=\"true\"><\/a>\u7b2c6\u7ae0-\u9002\u914d\u5668\uff1a\u8bbe\u8ba1\u66f4\u5b89\u5168\u65b9\u4fbf\u7684Queue<\/h3>\n<p dir=\"auto\">STL\u4e2d<code>queue<\/code>\u662f\u4e00\u4e2aFIFO\u961f\u5217\uff0c\u63d0\u4f9b\u7684\u6838\u5fc3\u63a5\u53e3\u51fd\u6570\u4e3a<\/p>\n<ul dir=\"auto\">\n<li>push( ) : \u63d2\u5165\u4e00\u4e2a\u5143\u7d20\u5230\u961f\u5217\u4e2d<\/li>\n<li>front( ) : \u8fd4\u56de\u961f\u9996\u5143\u7d20<\/li>\n<li>back( ) : \u8fd4\u56de\u961f\u5c3e\u5143\u7d20<\/li>\n<li>pop( ) : \u79fb\u9664\u961f\u9996\u5143\u7d20<\/li>\n<\/ul>\n<p dir=\"auto\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5728STL\u5934\u6587\u4ef6<code>&lt;queue&gt;<\/code>\u4e2d<code>queue<\/code>\u4e2d\u5b9a\u4e49\uff1a<\/p>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre><span class=\"pl-k\">namespace<\/span> <span class=\"pl-en\">std<\/span>\r\n{\r\n    <span class=\"pl-k\">template<\/span>&lt;<span class=\"pl-k\">typename<\/span> T, <span class=\"pl-k\">typename<\/span> Container = deque&lt;T&gt; &gt;\r\n    <span class=\"pl-k\">class<\/span> <span class=\"pl-en\">queue<\/span>;\r\n}<\/pre>\n<\/div>\n<p dir=\"auto\">\u6ce8\u610f\u5230\u7b2c\u4e8c\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u8bf4\u660e\u5728<code>queue<\/code>\u4e2d\u9ed8\u8ba4\u4f7f\u7528<code>deuqe<\/code>\u4f5c\u4e3a\u5b9e\u9645\u5b58\u50a8<code>T<\/code>\u7c7b\u7684\u5bb9\u5668, \u5f53\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u63d0\u4f9b\u6210\u5458\u51fd\u6570<code>front()<\/code>\u3001<code>back()<\/code>\u3001<code>push_back()<\/code>\u548c<code>pop_front()<\/code>\u7684\u5e8f\u5217\u5bb9\u5668\u7c7b\uff0c\u5982<code>list<\/code>\u3002\u6807\u51c6\u5e93\u4e2d\u7684<code>queue<\/code>\u7684\u5b9e\u73b0\u66f4\u6ce8\u91cd\u6548\u7387\u800c\u4e0d\u662f\u65b9\u4fbf\u548c\u5b89\u5168\u3002\u8fd9\u5e76\u4e0d\u662f\u9002\u5408\u4e8e\u6240\u6709\u573a\u5408\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u4e00\u4e2a\u63d0\u4f9b<code>deque<\/code>\u5bb9\u5668\u505a\u51fa\u4fee\u6539\uff0c\u9002\u914d\u51fa\u4e00\u4e2a\u4e0d\u540c\u4e8e\u6807\u51c6\u5e93\u4f46\u7b26\u5408\u81ea\u5df1\u98ce\u683c\u7684<code>Queue<\/code>\u3002<\/p>\n<p dir=\"auto\">\u4e0b\u9762\u5b9e\u73b0\u7684Queue\u63d0\u4f9b\u4e86\u629b\u51fa\u5f02\u5e38\u7684\u5904\u7406\uff0c\u4ee5\u53ca\u8fd4\u56de\u961f\u9996\u5143\u7d20\u7684\u65b0\u7684<code>pop<\/code>\u65b9\u6cd5\u3002<\/p>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre><span class=\"pl-k\">template <\/span>&lt;<span class=\"pl-k\">typename<\/span> T,  Container = deque&lt;T&gt; &gt;\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">Queue<\/span>\r\n{\r\n    <span class=\"pl-k\">protected:<\/span>\r\n        Container c;\r\n        \r\n        <span class=\"pl-c\">\/\/\u5f02\u5e38\u7c7b\uff1a\u5728\u4e00\u4e2a\u7a7a\u961f\u5217\u4e2d\u8c03\u7528 pop() \u548c front() <\/span>\r\n        <span class=\"pl-k\">class<\/span> <span class=\"pl-en\">EmptyQueue<\/span> : <span class=\"pl-k\">public<\/span> <span class=\"pl-en\">exception<\/span>\r\n        {\r\n            <span class=\"pl-k\">public:<\/span>\r\n                <span class=\"pl-k\">virtual<\/span> <span class=\"pl-k\">const<\/span> <span class=\"pl-k\">char<\/span>* what <span class=\"pl-k\">const<\/span> <span class=\"pl-en\">throw<\/span>( )\r\n                {\r\n                    <span class=\"pl-k\">return<\/span> <span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>empty queue!<span class=\"pl-pds\">\"<\/span><\/span>;\r\n                }\r\n            \r\n        }\r\n        \r\n        <span class=\"pl-k\">typename<\/span> Container::size_type <span class=\"pl-en\">size<\/span>( ) <span class=\"pl-k\">const<\/span>\r\n        {\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">size<\/span>( );\r\n        }\r\n        \r\n        <span class=\"pl-k\">bool<\/span> <span class=\"pl-en\">empty<\/span>( ) bool \r\n        {\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">empty<\/span>();\r\n        }\r\n\r\n        <span class=\"pl-k\">void<\/span> <span class=\"pl-en\">push<\/span>( <span class=\"pl-k\">const<\/span> T&amp; item )\r\n        {\r\n            c.<span class=\"pl-c1\">push<\/span>( item );\r\n        }\r\n        \r\n        <span class=\"pl-k\">void<\/span> <span class=\"pl-en\">push<\/span>( T&amp;&amp; item )\r\n        {\r\n            c.<span class=\"pl-c1\">push<\/span>( item );\r\n        }\r\n\r\n        <span class=\"pl-k\">const<\/span> T&amp; <span class=\"pl-en\">front<\/span>( ) <span class=\"pl-k\">const<\/span>\r\n        {\r\n            <span class=\"pl-k\">if<\/span>( c.<span class=\"pl-c1\">empty<\/span>( ) )\r\n                <span class=\"pl-k\">throw<\/span> <span class=\"pl-smi\">EmptyQueue<\/span>();\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">front<\/span>();\r\n        }\r\n        \r\n        T&amp; <span class=\"pl-en\">front<\/span>( )\r\n        {\r\n             <span class=\"pl-k\">if<\/span>( c.<span class=\"pl-c1\">empty<\/span>( ) )\r\n                <span class=\"pl-k\">throw<\/span> <span class=\"pl-smi\">EmptyQueue<\/span>( );\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">front<\/span>( );\r\n        }\r\n\r\n        <span class=\"pl-k\">const<\/span> T&amp; <span class=\"pl-en\">back<\/span>( ) <span class=\"pl-k\">const<\/span>\r\n        {\r\n            <span class=\"pl-k\">if<\/span>( c.<span class=\"pl-c1\">empty<\/span>( ) )\r\n                <span class=\"pl-k\">throw<\/span> <span class=\"pl-smi\">EmptyQueue<\/span>();\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">back<\/span>();\r\n        }\r\n        \r\n        T&amp; <span class=\"pl-en\">front<\/span>( )\r\n        {\r\n             <span class=\"pl-k\">if<\/span>( c.<span class=\"pl-c1\">empty<\/span>( ) )\r\n                <span class=\"pl-k\">throw<\/span> <span class=\"pl-smi\">EmptyQueue<\/span>( );\r\n            <span class=\"pl-k\">return<\/span> c.<span class=\"pl-c1\">back<\/span>( );\r\n        }\r\n\r\n        <span class=\"pl-c\">\/\/ \u8fd4\u56de\u961f\u9996\u5143\u7d20<\/span>\r\n        T <span class=\"pl-en\">pop<\/span>( ) <span class=\"pl-k\">const<\/span> \r\n        {\r\n            <span class=\"pl-k\">if<\/span>( c.<span class=\"pl-c1\">empty<\/span>() )\r\n                <span class=\"pl-k\">throw<\/span> <span class=\"pl-smi\">EmptyQueue<\/span>();\r\n            \r\n            T <span class=\"pl-smi\">elem<\/span>( c.<span class=\"pl-c1\">front<\/span>( ) );\r\n            c.<span class=\"pl-c1\">pop<\/span>();\r\n            <span class=\"pl-k\">return<\/span> elem;\r\n        }\r\n        \r\n};\r\n<\/pre>\n<\/div>\n<h3 dir=\"auto\"><a id=\"user-content-\u7b2c7\u7ae0-\u6865\u63a5pimpl\u7f16\u7a0b\u6280\u6cd5-\u51cf\u5c11\u7f16\u8bd1\u4f9d\u8d56\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%AC%AC7%E7%AB%A0-%E6%A1%A5%E6%8E%A5pimpl%E7%BC%96%E7%A8%8B%E6%8A%80%E6%B3%95-%E5%87%8F%E5%B0%91%E7%BC%96%E8%AF%91%E4%BE%9D%E8%B5%96\" aria-hidden=\"true\"><\/a>\u7b2c7\u7ae0-\u6865\u63a5\uff1aPimpl\u7f16\u7a0b\u6280\u6cd5-\u51cf\u5c11\u7f16\u8bd1\u4f9d\u8d56<\/h3>\n<p dir=\"auto\">PImpl\uff08Pointer to implementation\uff09\u662f\u4e00\u79cdC++\u7f16\u7a0b\u6280\u672f\uff0c\u5176\u901a\u8fc7\u5c06\u7c7b\u7684\u5b9e\u73b0\u7684\u8be6\u7ec6\u4fe1\u606f\u653e\u5728\u53e6\u4e00\u4e2a\u5355\u72ec\u7684\u7c7b\u4e2d\uff0c\u5e76\u901a\u8fc7\u4e0d\u900f\u660e\u7684\u6307\u9488\u6765\u8bbf\u95ee\u3002\u8fd9\u9879\u6280\u672f\u80fd\u591f\u5c06\u5b9e\u73b0\u7684\u7ec6\u8282\u4ece\u5176\u5bf9\u8c61\u4e2d\u53bb\u9664\uff0c\u8fd8\u80fd\u51cf\u5c11\u7f16\u8bd1\u4f9d\u8d56\u3002\u6709\u4eba\u5c06\u5176\u79f0\u4e3a\u201c\u7f16\u8bd1\u9632\u706b\u5899\uff08Compilation Firewalls\uff09\u201d\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-pimpl\u6280\u6cd5\u7684\u5b9a\u4e49\u548c\u7528\u5904\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#pimpl%E6%8A%80%E6%B3%95%E7%9A%84%E5%AE%9A%E4%B9%89%E5%92%8C%E7%94%A8%E5%A4%84\" aria-hidden=\"true\"><\/a>Pimpl\u6280\u6cd5\u7684\u5b9a\u4e49\u548c\u7528\u5904<\/h4>\n<p dir=\"auto\">\u5728C ++\u4e2d\uff0c\u5982\u679c\u5934\u6587\u4ef6\u7c7b\u5b9a\u4e49\u4e2d\u7684\u4efb\u4f55\u5185\u5bb9\u53d1\u751f\u66f4\u6539\uff0c\u5219\u5fc5\u987b\u91cd\u65b0\u7f16\u8bd1\u8be5\u7c7b\u7684\u6240\u6709\u7528\u6237-\u5373\u4f7f\u552f\u4e00\u7684\u66f4\u6539\u662f\u8be5\u7c7b\u7528\u6237\u751a\u81f3\u65e0\u6cd5\u8bbf\u95ee\u7684\u79c1\u6709\u7c7b\u6210\u5458\u3002\u8fd9\u662f\u56e0\u4e3aC ++\u7684\u6784\u5efa\u6a21\u578b\u57fa\u4e8e\u6587\u672c\u5305\u542b\uff08textual inclusion\uff09\uff0c\u5e76\u4e14\u56e0\u4e3aC ++\u5047\u5b9a\u8c03\u7528\u8005\u77e5\u9053\u4e00\u4e2a\u7c7b\u7684\u4e24\u4e2a\u4e3b\u8981\u65b9\u9762\uff0c\u800c\u8fd9\u4e24\u4e2a\u53ef\u80fd\u4f1a\u53d7\u5230\u79c1\u6709\u6210\u5458\u7684\u5f71\u54cd\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u56e0\u4e3a\u7c7b\u7684\u79c1\u6709\u6570\u636e\u6210\u5458\u53c2\u4e0e\u5176\u5bf9\u8c61\u8868\u793a\uff0c\u5f71\u54cd\u5927\u5c0f\u548c\u5e03\u5c40\uff0c<\/li>\n<li>\u4e5f\u56e0\u4e3a\u7c7b\u7684\u79c1\u6709\u6210\u5458\u51fd\u6570\u53c2\u4e0e\u91cd\u8f7d\u51b3\u8bae\uff08\u8fd9\u53d1\u751f\u4e8e\u6210\u5458\u8bbf\u95ee\u68c0\u67e5\u4e4b\u524d\uff09\uff0c\u6545\u5bf9\u5b9e\u73b0\u7ec6\u8282\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u8981\u6c42\u8be5\u7c7b\u7684\u6240\u6709\u7528\u6237\u91cd\u7f16\u8bd1\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u4e3a\u4e86\u51cf\u5c11\u8fd9\u4e9b\u7f16\u8bd1\u4f9d\u8d56\u6027\uff0c\u4e00\u79cd\u5e38\u89c1\u7684\u6280\u672f\u662f\u4f7f\u7528\u4e0d\u900f\u660e\u7684\u6307\u9488\u6765\u9690\u85cf\u4e00\u4e9b\u5b9e\u73b0\u7ec6\u8282\u3002\u8fd9\u662f\u57fa\u672c\u6982\u5ff5\uff1a<\/p>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre><span class=\"pl-c\">\/\/ Pimpl idiom - basic idea<\/span>\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">widget<\/span> {\r\n    <span class=\"pl-c\">\/\/ :::<\/span>\r\n<span class=\"pl-k\">private:<\/span>\r\n    <span class=\"pl-k\">struct<\/span> <span class=\"pl-en\">impl<\/span>;        <span class=\"pl-c\">\/\/ things to be hidden go here<\/span>\r\n    impl* pimpl_;       <span class=\"pl-c\">\/\/ opaque pointer to forward-declared class<\/span>\r\n};<\/pre>\n<\/div>\n<p dir=\"auto\">\u7c7bwidget\u4f7f\u7528\u4e86handle\/body\u7f16\u7a0b\u6280\u6cd5\u7684\u53d8\u4f53\u3002handle\/body\u4e3b\u8981\u7528\u4e8e\u5bf9\u4e00\u4e2a\u5171\u4eab\u5b9e\u73b0\u7684\u5f15\u7528\u8ba1\u6570\uff0c\u4f46\u662f\u5b83\u4e5f\u5177\u6709\u66f4\u4e00\u822c\u7684\u5b9e\u73b0\u9690\u85cf\u7528\u6cd5\u3002\u4e3a\u4e86\u65b9\u4fbf\u8d77\u89c1\uff0c\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u5c06widget\u79f0\u4e3a\u201c\u53ef\u89c1\u7c7b\u201d\uff0c\u5c06impl\u79f0\u4e3a\u201c Pimpl\u7c7b\u201d\u3002<\/p>\n<p dir=\"auto\">\u7f16\u7a0b\u6280\u6cd5\u7684\u4e00\u5927\u4f18\u52bf\u662f\uff0c\u5b83\u6253\u7834\u4e86\u7f16\u8bd1\u65f6\u7684\u4f9d\u8d56\u6027\u3002\u9996\u5148\uff0c\u7cfb\u7edf\u6784\u5efa\u8fd0\u884c\u5f97\u66f4\u5feb\uff0c\u56e0\u4e3a\u4f7f\u7528Pimpl\u53ef\u4ee5\u6d88\u9664\u989d\u5916\u7684#include\u3002\u6211\u4ece\u4e8b\u8fc7\u4e00\u4e9b\u9879\u76ee\uff0c\u5728\u8fd9\u4e9b\u9879\u76ee\u4e2d\uff0c\u4ec5\u5c06\u51e0\u4e2a\u5e7f\u4e3a\u53ef\u89c1\u7684\u7c7b\u8f6c\u6362\u4e3a\u4f7f\u7528Pimpls\u5373\u53ef\u4f7f\u7cfb\u7edf\u7684\u6784\u5efa\u65f6\u95f4\u51cf\u5c11\u4e00\u534a\u3002\u5176\u6b21\uff0c\u5b83\u53ef\u4ee5\u672c\u5730\u5316\u4ee3\u7801\u66f4\u6539\u7684\u6784\u5efa\u5f71\u54cd\uff0c\u56e0\u4e3a\u53ef\u4ee5\u81ea\u7531\u66f4\u6539\u9a7b\u7559\u5728Pimpl\u4e2d\u7684\u7c7b\u7684\u5404\u4e2a\u90e8\u5206\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5\u81ea\u7531\u6dfb\u52a0\u6216\u5220\u9664\u6210\u5458\uff0c\u800c\u65e0\u9700\u91cd\u65b0\u7f16\u8bd1\u5ba2\u6237\u7aef\u4ee3\u7801\u3002\u7531\u4e8e\u5b83\u975e\u5e38\u64c5\u957f\u6d88\u9664\u4ec5\u7531\u4e8e\u73b0\u5728\u9690\u85cf\u7684\u6210\u5458\u7684\u66f4\u6539\u800c\u5bfc\u81f4\u7684\u7f16\u8bd1\u7ea7\u8054\uff0c\u56e0\u6b64\u901a\u5e38\u88ab\u79f0\u4e3a\u201c\u7f16\u8bd1\u9632\u706b\u5899\u201d\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-pimpl\u6280\u6cd5\u7684\u5b9e\u8df5\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#pimpl%E6%8A%80%E6%B3%95%E7%9A%84%E5%AE%9E%E8%B7%B5\" aria-hidden=\"true\"><\/a>Pimpl\u6280\u6cd5\u7684\u5b9e\u8df5<\/h4>\n<p dir=\"auto\">\u907f\u514d\u4f7f\u7528\u539f\u751f\u6307\u9488\u548c\u663e\u5f0f\u7684<code>delete<\/code>\u3002\u8981\u4ec5\u4f7f\u7528C++\u6807\u51c6\u8bbe\u65bd\u8868\u8fbe<code>Pimpl<\/code>\uff0c\u6700\u5408\u9002\u7684\u9009\u62e9\u662f\u901a\u8fc7<code>unique_ptr<\/code>\u6765\u4fdd\u5b58<code>Pimpl<\/code>\u5bf9\u8c61\uff0c\u56e0\u4e3aPimpl\u5bf9\u8c61\u552f\u4e00\u88ab\u53ef\u89c1\u7c7b\u62e5\u6709\u3002\u4f7f\u7528<code>unique_ptr<\/code>\u7684\u4ee3\u7801\u5f88\u7b80\u5355\uff1a<\/p>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre><span class=\"pl-c\">\/\/ in header file<\/span>\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">widget<\/span> {\r\n<span class=\"pl-k\">public:<\/span>\r\n    <span class=\"pl-en\">widget<\/span>();\r\n    <span class=\"pl-en\">~widget<\/span>();\r\n<span class=\"pl-k\">private:<\/span>\r\n    <span class=\"pl-k\">class<\/span> <span class=\"pl-en\">impl<\/span>;\r\n    unique_ptr&lt;impl&gt; pimpl;\r\n};\r\n \r\n<span class=\"pl-c\">\/\/ in implementation file<\/span>\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">widget<\/span>::impl {\r\n    <span class=\"pl-c\">\/\/ :::<\/span>\r\n};\r\n \r\n<span class=\"pl-en\">widget::widget<\/span>() : pimpl{ <span class=\"pl-k\">new<\/span> impl{ <span class=\"pl-c\">\/*...*\/<\/span> } } { }\r\n<span class=\"pl-en\">widget::~widget<\/span>() { }                   <span class=\"pl-c\">\/\/ or =default<\/span>\r\n<\/pre>\n<\/div>\n<p dir=\"auto\">\/\/TODO: handle\/body\u7f16\u7a0b\u6280\u6cd5<\/p>\n<h4 dir=\"auto\"><\/h4>\n<h3 dir=\"auto\"><a id=\"user-content-\u7b2c12\u7ae0-\u4ee3\u7406\u5b9e\u73b0\u4e00\u4e2a\u534a\u7ebf\u7a0b\u5b89\u5168\u7684\u667a\u80fd\u6307\u9488\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%AC%AC12%E7%AB%A0-%E4%BB%A3%E7%90%86%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E5%8D%8A%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88\" aria-hidden=\"true\"><\/a>\u7b2c12\u7ae0-\u4ee3\u7406\uff1a\u5b9e\u73b0\u4e00\u4e2a\u534a\u7ebf\u7a0b\u5b89\u5168\u7684\u667a\u80fd\u6307\u9488<\/h3>\n<ol dir=\"auto\">\n<li>\u667a\u80fd\u6307\u9488(shared_ptr)\u7ebf\u7a0b\u5b89\u5168\u5417?<\/li>\n<\/ol>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">\uff08&#8221;half thread-safe&#8221;\uff09<\/p>\n<\/li>\n<li>\n<p dir=\"auto\">\u662f: \u5f15\u7528\u8ba1\u6570\u63a7\u5236\u5355\u5143\u7ebf\u7a0b\u5b89\u5168, \u4fdd\u8bc1\u5bf9\u8c61\u53ea\u88ab\u91ca\u653e\u4e00\u6b21<\/p>\n<\/li>\n<li>\n<p dir=\"auto\">\u5426: \u5bf9\u4e8e\u6570\u636e\u7684\u8bfb\u5199\u6ca1\u6709\u7ebf\u7a0b\u5b89\u5168<\/p>\n<\/li>\n<\/ul>\n<ol dir=\"auto\" start=\"2\">\n<li>\u5982\u4f55\u5c06\u667a\u80fd\u6307\u9488\u53d8\u6210\u7ebf\u7a0b\u5b89\u5168?<\/li>\n<\/ol>\n<ul dir=\"auto\">\n<li>\u4f7f\u7528 mutex \u63a7\u5236\u667a\u80fd\u6307\u9488\u7684\u8bbf\u95ee<\/li>\n<li>\u4f7f\u7528\u5168\u5c40\u975e\u6210\u5458\u539f\u5b50\u64cd\u4f5c\u51fd\u6570\u8bbf\u95ee, \u8bf8\u5982: std::atomic_load(), atomic_store(), \u2026<\/li>\n<li>\u7f3a\u70b9: \u5bb9\u6613\u51fa\u9519, \u5fd8\u8bb0\u4f7f\u7528\u8fd9\u4e9b\u64cd\u4f5c<\/li>\n<li>C++20: atomic&lt;shared_ptr&gt;, atomic&lt;weak_ptr&gt; std::atomic_shared_ptrand astd::atomic_weak_ptr.<\/li>\n<li>\u5185\u90e8\u539f\u7406\u53ef\u80fd\u4f7f\u7528\u4e86 mutex<\/li>\n<li>\u5168\u5c40\u975e\u6210\u5458\u539f\u5b50\u64cd\u4f5c\u51fd\u6570\u6807\u8bb0\u4e3a\u4e0d\u63a8\u8350\u4f7f\u7528(deprecated)<\/li>\n<\/ul>\n<ol dir=\"auto\" start=\"3\">\n<li>\u6570\u636e\u7ade\u4e89<\/li>\n<\/ol>\n<ul dir=\"auto\">\n<li>\u4e00\u4e2ashared_ptr\u5bf9\u8c61\u5b9e\u4f53\u53ef\u4ee5\u88ab\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6<\/li>\n<li>\u4e24\u4e2ashared_ptr\u5bf9\u8c61\u5b9e\u4f53\u53ef\u4ee5\u88ab\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u5199\u5165\uff0c&#8221;\u6790\u6784&#8221;\u7b97\u5199\u64cd\u4f5c<\/li>\n<li>\u5982\u679c\u8981\u4ece\u591a\u4e2a\u7ebf\u7a0b\u8bfb\u5199\u540c\u4e00\u4e2ashared_ptr,\u90a3\u4e48\u9700\u8981\u52a0\u9501\u3002<\/li>\n<\/ul>\n<ol dir=\"auto\" start=\"4\">\n<li>\u4ee3\u7801\u5b9e\u73b0<\/li>\n<\/ol>\n<div class=\"highlight highlight-source-c++ position-relative overflow-auto\">\n<pre>#<span class=\"pl-k\">include<\/span> <span class=\"pl-s\"><span class=\"pl-pds\">&lt;<\/span>atomic<span class=\"pl-pds\">&gt;<\/span><\/span>\r\n\r\n<span class=\"pl-c\">\/\/ \u975e\u5b8c\u5168\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/span>\r\n<span class=\"pl-c\">\/\/ \u5f15\u7528\u8ba1\u6570<\/span>\r\n<span class=\"pl-k\">template<\/span>&lt;<span class=\"pl-k\">typename<\/span> T&gt;\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">ReferenceCounter<\/span>\r\n{\r\n    \r\n    <span class=\"pl-en\">ReferenceCounter<\/span>( ):count(<span class=\"pl-c1\">0<\/span>) {};\r\n    <span class=\"pl-en\">ReferenceCounter<\/span>(<span class=\"pl-k\">const<\/span> ReferenceCounter&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n    ReferenceCounter&amp; <span class=\"pl-k\">operator<\/span>=(<span class=\"pl-k\">const<\/span> ReferenceCounter&amp;) = <span class=\"pl-k\">delete<\/span>;\r\n    <span class=\"pl-en\">ReferenceCounter<\/span>(ReferenceCounter&amp;&amp;) = <span class=\"pl-k\">default<\/span>\r\n    ReferenceCounter&amp; <span class=\"pl-k\">operator<\/span>=(ReferenceCounter&amp;&amp;) = <span class=\"pl-k\">default<\/span>;\r\n    <span class=\"pl-c\">\/\/ \u524d\u7f6e++, \u8fd9\u91cc\u4e0d\u63d0\u4f9b\u540e\u7f6e\uff0c\u56e0\u4e3a\u540e\u7f6e\u8fd4\u56de\u4e00\u4e2aReferenceCounter\u7684\u62f7\u8d1d\uff0c\u800c\u4e4b\u524d\u7981\u6b62ReferenceCounter\u62f7\u8d1d\u3002<\/span>\r\n    ReferenceCounter&amp; <span class=\"pl-k\">operator<\/span>++()\r\n    {   \r\n        count.<span class=\"pl-c1\">fetch_add<\/span>(<span class=\"pl-c1\">1<\/span>);\r\n        <span class=\"pl-k\">return<\/span> *<span class=\"pl-c1\">this<\/span>;\r\n    }\r\n\r\n    ReferenceCounter&amp; <span class=\"pl-k\">operator<\/span>--()\r\n    {\r\n        count.<span class=\"pl-c1\">fetch_sub<\/span>(<span class=\"pl-c1\">1<\/span>);\r\n        <span class=\"pl-k\">return<\/span> *<span class=\"pl-c1\">this<\/span>;\r\n    }\r\n\r\n    <span class=\"pl-c1\">size_t<\/span> <span class=\"pl-en\">getCount<\/span>() <span class=\"pl-k\">const<\/span> \r\n    {\r\n        <span class=\"pl-k\">return<\/span> count.<span class=\"pl-c1\">load<\/span>();\r\n    }\r\n\r\n    <span class=\"pl-k\">private:<\/span>\r\n        <span class=\"pl-c\">\/\/ \u539f\u5b50\u7c7b\u578b\uff0c\u6216\u4e0a\u9501<\/span>\r\n        std::atomic&lt;<span class=\"pl-c1\">size_t<\/span>&gt; count;\r\n        \r\n};\r\n\r\n<span class=\"pl-k\">template <\/span>&lt;<span class=\"pl-k\">typename<\/span> T&gt;\r\n<span class=\"pl-k\">class<\/span> <span class=\"pl-en\">SharedPtr<\/span>{\r\n    \r\n    <span class=\"pl-k\">explicit<\/span> <span class=\"pl-en\">SharedPtr<\/span>(T* ptr_ = <span class=\"pl-c1\">nullptr<\/span>) : ptr(ptr_) {\r\n        count = <span class=\"pl-k\">new<\/span> <span class=\"pl-c1\">ReferenceCounter<\/span>();\r\n        <span class=\"pl-k\">if<\/span>(ptr)\r\n        {\r\n            ++(*count);\r\n        } \r\n    }\r\n    <span class=\"pl-en\">~SharedPtr<\/span>() {\r\n        --(*count);\r\n        <span class=\"pl-k\">if<\/span>(count-&gt;<span class=\"pl-c1\">getCount<\/span>() == <span class=\"pl-c1\">0<\/span>)\r\n        {\r\n            <span class=\"pl-k\">delete<\/span> ptr;\r\n            <span class=\"pl-k\">delete<\/span> count;\r\n        }\r\n    }\r\n\r\n    <span class=\"pl-en\">SharedPtr<\/span>(<span class=\"pl-k\">const<\/span> SharedPtr&lt;T&gt;&amp; other) : \r\n        <span class=\"pl-en\">ptr<\/span>(other.ptr), \r\n        <span class=\"pl-en\">count<\/span>(other.count)\r\n    {\r\n        ++(*count);\r\n    }\r\n\r\n    SharedPtr&lt;T&gt;&amp; <span class=\"pl-k\">operator<\/span>= (<span class=\"pl-k\">const<\/span> SharedPtr&lt;T&gt;&amp; other)\r\n    {\r\n        <span class=\"pl-k\">if<\/span>(<span class=\"pl-c1\">this<\/span> != &amp;other)\r\n        {\r\n            --(*count);\r\n            <span class=\"pl-k\">if<\/span>(count.<span class=\"pl-c1\">getCount<\/span>() == <span class=\"pl-c1\">0<\/span>)\r\n            {\r\n                <span class=\"pl-k\">delete<\/span> count;\r\n                <span class=\"pl-k\">delete<\/span> ptr;\r\n            }\r\n            ptr = other.<span class=\"pl-smi\">ptr<\/span>;\r\n            count = other.<span class=\"pl-smi\">count<\/span>;\r\n            ++(*count);\r\n        }\r\n        <span class=\"pl-k\">return<\/span> *<span class=\"pl-c1\">this<\/span>;   \r\n    }\r\n\r\n    <span class=\"pl-en\">SharedPtr<\/span>(SharedPtr&amp;&amp; other) = <span class=\"pl-k\">default<\/span>;\r\n    SharedPtr&amp; <span class=\"pl-k\">operator<\/span>=(SharedPtr&amp;&amp; other) = <span class=\"pl-k\">default<\/span>;\r\n\r\n    T&amp; <span class=\"pl-k\">operator<\/span>*() <span class=\"pl-k\">const<\/span> { <span class=\"pl-k\">return<\/span> *ptr; }\r\n    T* <span class=\"pl-k\">operator<\/span>-&gt;() <span class=\"pl-k\">const<\/span>{\r\n        <span class=\"pl-k\">return<\/span> ptr;\r\n    }\r\n    T* <span class=\"pl-en\">get<\/span>() <span class=\"pl-k\">const<\/span> { <span class=\"pl-k\">return<\/span> ptr; }\r\n    \r\n    <span class=\"pl-k\">int<\/span> <span class=\"pl-en\">use_count<\/span>() <span class=\"pl-k\">const<\/span> { <span class=\"pl-k\">return<\/span> count-&gt;<span class=\"pl-c1\">getCount<\/span>(); }\r\n\r\n    <span class=\"pl-k\">bool<\/span> <span class=\"pl-en\">unique<\/span>() <span class=\"pl-k\">const<\/span> { <span class=\"pl-k\">return<\/span> <span class=\"pl-c1\">use_count<\/span>() == <span class=\"pl-c1\">1<\/span>; }\r\n\r\n    <span class=\"pl-k\">private:<\/span>\r\n        T* ptr;\r\n        ReferenceCounter* count;\r\n}<\/pre>\n<\/div>\n<ol dir=\"auto\" start=\"5\">\n<li>\u91cd\u65b0\u56de\u987eC++\u7ebf\u7a0b\u6c60\u4e2d\u4f7f\u7528\u7684\u865a\u8c03\u7528\u65b9\u6cd5<\/li>\n<\/ol>\n<h3 dir=\"auto\"><a id=\"user-content-\u7b2c20\u7ae0\u89c2\u5bdf\u8005\u6a21\u5f0f\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%AC%AC20%E7%AB%A0%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F\" aria-hidden=\"true\"><\/a>\u7b2c20\u7ae0\uff1a\u89c2\u5bdf\u8005\u6a21\u5f0f<\/h3>\n<p dir=\"auto\">\u4ece\u89c2\u5bdf\u8005\u6a21\u5f0f\u51fa\u53d1\uff0c\u4e86\u89e3\u4e86\u53d1\u5e03\u8ba2\u9605\u6a21\u5f0f\uff0c\u5230\u6d88\u606f\u961f\u5217\uff0c\u518d\u5230\u7528redis\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u4ee5\u53ca\u5b9e\u73b0\u6d88\u606f\u961f\u5217\u7684\u6ce8\u610f\u4e8b\u9879<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u89c2\u5bdf\u8005\u6a21\u5f0f\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%A7%82%E5%AF%9F%E8%80%85%E6%A8%A1%E5%BC%8F\" aria-hidden=\"true\"><\/a>\u89c2\u5bdf\u8005\u6a21\u5f0f<\/h4>\n<h4 dir=\"auto\"><a id=\"user-content-\u53d1\u5e03\u8ba2\u9605\u6a21\u5f0f\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%8F%91%E5%B8%83%E8%AE%A2%E9%98%85%E6%A8%A1%E5%BC%8F\" aria-hidden=\"true\"><\/a>\u53d1\u5e03\u8ba2\u9605\u6a21\u5f0f<\/h4>\n<ul dir=\"auto\">\n<li>\u53d1\u5e03\u8005\u548c\u8ba2\u9605\u8005\u4e0d\u76f4\u63a5\u5173\u8054\uff0c\u501f\u52a9\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u4e86\u677e\u8026\u5408\uff0c\u964d\u4f4e\u4e86\u590d\u6742\u5ea6\uff0c\u540c\u65f6\u63d0\u9ad8\u4e86\u7cfb\u7edf\u7684\u53ef\u4f38\u7f29\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/li>\n<li>\u5f02\u6b65<\/li>\n<\/ul>\n<h4 dir=\"auto\"><a id=\"user-content-\u6d88\u606f\u961f\u5217\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97\" aria-hidden=\"true\"><\/a>\u6d88\u606f\u961f\u5217<\/h4>\n<h5 dir=\"auto\"><a id=\"user-content-\u4f7f\u7528redis\u5b9e\u73b0\u6d88\u606f\u961f\u5217\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E4%BD%BF%E7%94%A8redis%E5%AE%9E%E7%8E%B0%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97\" aria-hidden=\"true\"><\/a>\u4f7f\u7528redis\u5b9e\u73b0\u6d88\u606f\u961f\u5217<\/h5>\n<ul dir=\"auto\">\n<li>\u5982\u4f55\u4fdd\u8bc1\u6709\u5e8f\uff1aFIFO\u6570\u636e\u7ed3\u6784<\/li>\n<li>\u5982\u4f55\u4fdd\u8bc1\u4e0d\u91cd\u590d\uff1a\u5168\u5c40Id(LIST\u6cd51\uff1a\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u7ea6\u5b9a\u597d\uff1bSTREAMS\u6cd5\u4e8c\uff1a\u6d88\u606f\u961f\u5217\u81ea\u52a8\u4ea7\u751f\uff08\u65f6\u95f4\u6233\uff09)<\/li>\n<li>\u5982\u4f55\u4fdd\u8bc1\u53ef\u9760\u6027\uff1a\u5907\u4efd<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u529f\u80fd\u548c\u9002\u7528\u573a\u666f<\/th>\n<th align=\"left\">\u57fa\u4e8eList<\/th>\n<th align=\"left\">\u57fa\u4e8eStreams<\/th>\n<th align=\"left\">\u5907\u6ce8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">\u9002\u7528\u573a\u666f<\/td>\n<td align=\"left\">Redis5.0\u7248\u672c\u7684\u90e8\u7f72\u73af\u5883\uff0c\u6d88\u606f\u603b\u91cf\u5c0f<\/td>\n<td align=\"left\">Redis5.0\u53ca\u4ee5\u540e\u7684\u7248\u672c\u7684\u90e8\u7f72\u73af\u5883\uff0c\u6d88\u606f\u603b\u91cf\u5927\uff0c\u9700\u8981\u6d88\u8d39\u7ec4\u5f62\u5f0f\u8bfb\u53d6\u6570\u636e<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6d88\u606f\u4fdd\u5e8f<\/td>\n<td align=\"left\">LPUSH\/RPOP<\/td>\n<td align=\"left\">XADD\/XREAD<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u963b\u585e\u8bfb\u53d6<\/td>\n<td align=\"left\">BRPOP<\/td>\n<td align=\"left\">XREAD block<\/td>\n<td align=\"left\">\u963b\u585e\u5f0f\u8bfb\u53d6\u5728\u5ba2\u6237\u7aef\u6ca1\u6709\u8bfb\u5230\u961f\u5217\u6570\u636e\u65f6\uff0c\u81ea\u52a8\u963b\u585e\uff0c\u8282\u7701\u56e0\u4e0d\u65adpeek\u7684CPU\u5f00\u9500<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u91cd\u590d\u6d88\u606f\u5904\u7406<\/td>\n<td align=\"left\">\u751f\u4ea7\u8005\u81ea\u884c\u5b9e\u73b0\u5168\u5c40\u552f\u4e00ID<\/td>\n<td align=\"left\">STREAMs\u81ea\u884c\u751f\u6210\u5168\u5c40\u552f\u4e00ID<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6d88\u606f\u53ef\u9760\u6027<\/td>\n<td align=\"left\">\u9002\u7528BRPOPRPUSH<\/td>\n<td align=\"left\">\u4f7f\u7528PENDING List \u81ea\u52a8\u5b58\u7559\u6d88\u606f\uff0c\u4f7f\u7528XPENGDING\u67e5\u770b\uff0c\u4f7f\u7528XACK\u786e\u8ba4\u6d88\u606f<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5 dir=\"auto\"><a id=\"user-content-\u6d88\u606f\u961f\u5217\u7684\u6ce8\u610f\u4e8b\u9879\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E7%9A%84%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9\" aria-hidden=\"true\"><\/a>\u6d88\u606f\u961f\u5217\u7684\u6ce8\u610f\u4e8b\u9879<\/h5>\n<p dir=\"auto\">\u5728\u4f7f\u7528\u6d88\u606f\u961f\u5217\u65f6\uff0c\u91cd\u70b9\u9700\u8981\u5173\u6ce8\u7684\u662f\u5982\u4f55\u4fdd\u8bc1\u4e0d\u4e22\u6d88\u606f\uff1f<\/p>\n<p dir=\"auto\">\u90a3\u4e48\u4e0b\u9762\u5c31\u6765\u5206\u6790\u4e00\u4e0b\uff0c\u54ea\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f1a\u4e22\u6d88\u606f\uff0c\u4ee5\u53ca\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n<p dir=\"auto\">1\u3001\u751f\u4ea7\u8005\u5728\u53d1\u5e03\u6d88\u606f\u65f6\u5f02\u5e38\uff1a<\/p>\n<p dir=\"auto\">a) \u7f51\u7edc\u6545\u969c\u6216\u5176\u4ed6\u95ee\u9898\u5bfc\u81f4\u53d1\u5e03\u5931\u8d25\uff08\u76f4\u63a5\u8fd4\u56de\u9519\u8bef\uff0c\u6d88\u606f\u6839\u672c\u6ca1\u53d1\u51fa\u53bb\uff09 b) \u7f51\u7edc\u6296\u52a8\u5bfc\u81f4\u53d1\u5e03\u8d85\u65f6\uff08\u53ef\u80fd\u53d1\u9001\u6570\u636e\u5305\u6210\u529f\uff0c\u4f46\u8bfb\u53d6\u54cd\u5e94\u7ed3\u679c\u8d85\u65f6\u4e86\uff0c\u4e0d\u77e5\u9053\u7ed3\u679c\u5982\u4f55\uff09<\/p>\n<p dir=\"auto\">\u60c5\u51b5a\u8fd8\u597d\uff0c\u6d88\u606f\u6839\u672c\u6ca1\u53d1\u51fa\u53bb\uff0c\u90a3\u4e48\u91cd\u65b0\u53d1\u4e00\u6b21\u5c31\u597d\u4e86\u3002\u4f46\u662f\u60c5\u51b5b\u6ca1\u529e\u6cd5\u77e5\u9053\u5230\u5e95\u6709\u6ca1\u6709\u53d1\u5e03\u6210\u529f\uff0c\u6240\u4ee5\u4e5f\u53ea\u80fd\u518d\u53d1\u4e00\u6b21\u3002\u6240\u4ee5\u8fd9\u4e24\u79cd\u60c5\u51b5\uff0c\u751f\u4ea7\u8005\u90fd\u9700\u8981\u91cd\u65b0\u53d1\u5e03\u6d88\u606f\uff0c\u76f4\u5230\u6210\u529f\u4e3a\u6b62\uff08\u4e00\u822c\u8bbe\u5b9a\u4e00\u4e2a\u6700\u5927\u91cd\u8bd5\u6b21\u6570\uff0c\u8d85\u8fc7\u6700\u5927\u6b21\u6570\u4f9d\u65e7\u5931\u8d25\u7684\u9700\u8981\u62a5\u8b66\u5904\u7406\uff09\u3002\u8fd9\u5c31\u4f1a\u5bfc\u81f4\u6d88\u8d39\u8005\u53ef\u80fd\u4f1a\u6536\u5230\u91cd\u590d\u6d88\u606f\u7684\u95ee\u9898\uff0c\u6240\u4ee5\u6d88\u8d39\u8005\u9700\u8981\u4fdd\u8bc1\u5728\u6536\u5230\u91cd\u590d\u6d88\u606f\u65f6\uff0c\u4f9d\u65e7\u80fd\u4fdd\u8bc1\u4e1a\u52a1\u7684\u6b63\u786e\u6027\uff08\u8bbe\u8ba1\u5e42\u7b49\u903b\u8f91\uff09\uff0c\u4e00\u822c\u9700\u8981\u6839\u636e\u5177\u4f53\u4e1a\u52a1\u6765\u505a\uff0c\u4f8b\u5982\u4f7f\u7528\u6d88\u606f\u7684\u552f\u4e00ID\uff0c\u6216\u8005\u7248\u672c\u53f7\u914d\u5408\u4e1a\u52a1\u903b\u8f91\u6765\u5904\u7406\u3002<\/p>\n<p dir=\"auto\">2\u3001\u6d88\u8d39\u8005\u5728\u5904\u7406\u6d88\u606f\u65f6\u5f02\u5e38\uff1a<\/p>\n<p dir=\"auto\">\u4e5f\u5c31\u662f\u6d88\u8d39\u8005\u628a\u6d88\u606f\u62ff\u51fa\u6765\u4e86\uff0c\u4f46\u662f\u8fd8\u6ca1\u5904\u7406\u5b8c\uff0c\u6d88\u8d39\u8005\u5c31\u6302\u4e86\u3002\u8fd9\u79cd\u60c5\u51b5\uff0c\u9700\u8981\u6d88\u8d39\u8005\u6062\u590d\u65f6\uff0c\u4f9d\u65e7\u80fd\u5904\u7406\u4e4b\u524d\u6ca1\u6709\u6d88\u8d39\u6210\u529f\u7684\u6d88\u606f\u3002\u4f7f\u7528List\u5f53\u4f5c\u961f\u5217\u65f6\uff0c\u4e5f\u5c31\u662f\u5229\u7528\u8001\u5e08\u6587\u7ae0\u6240\u8bb2\u7684\u5907\u4efd\u961f\u5217\u6765\u4fdd\u8bc1\uff0c\u4ee3\u4ef7\u662f\u589e\u52a0\u4e86\u7ef4\u62a4\u8fd9\u4e2a\u5907\u4efd\u961f\u5217\u7684\u6210\u672c\u3002\u800cStreams\u5219\u662f\u91c7\u7528ack\u7684\u65b9\u5f0f\uff0c\u6d88\u8d39\u6210\u529f\u540e\u544a\u77e5\u4e2d\u95f4\u4ef6\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5904\u7406\u8d77\u6765\u66f4\u4f18\u96c5\uff0c\u6210\u719f\u7684\u961f\u5217\u4e2d\u95f4\u4ef6\u4f8b\u5982RabbitMQ\u3001Kafka\u90fd\u662f\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\u6765\u4fdd\u8bc1\u6d88\u8d39\u8005\u4e0d\u4e22\u6d88\u606f\u7684\u3002<\/p>\n<p dir=\"auto\">3\u3001\u6d88\u606f\u961f\u5217\u4e2d\u95f4\u4ef6\u4e22\u5931\u6d88\u606f<\/p>\n<p dir=\"auto\">\u4e0a\u97622\u4e2a\u5c42\u9762\u90fd\u6bd4\u8f83\u597d\u5904\u7406\uff0c\u53ea\u8981\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u914d\u5408\u597d\uff0c\u5c31\u80fd\u4fdd\u8bc1\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u90fd\u4e0d\u4e22\u6d88\u606f\u3002\u4f46\u662f\uff0c\u5982\u679c\u6d88\u606f\u961f\u5217\u4e2d\u95f4\u4ef6\u672c\u8eab\u5c31\u4e0d\u53ef\u9760\uff0c\u4e5f\u6709\u53ef\u80fd\u4f1a\u4e22\u5931\u6d88\u606f\uff0c\u6bd5\u7adf\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8fd9\u90fd\u4f9d\u8d56\u5b83\uff0c\u5982\u679c\u5b83\u4e0d\u53ef\u9760\uff0c\u90a3\u4e48\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u65e0\u8bba\u600e\u4e48\u505a\uff0c\u90fd\u65e0\u6cd5\u4fdd\u8bc1\u6570\u636e\u4e0d\u4e22\u5931\u3002<\/p>\n<p dir=\"auto\">a) \u5728\u7528Redis\u5f53\u4f5c\u961f\u5217\u6216\u5b58\u50a8\u6570\u636e\u65f6\uff0c\u662f\u6709\u53ef\u80fd\u4e22\u5931\u6570\u636e\u7684\uff1a\u4e00\u4e2a\u573a\u666f\u662f\uff0c\u5982\u679c\u6253\u5f00AOF\u5e76\u4e14\u662f\u6bcf\u79d2\u5199\u76d8\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5199\u76d8\u8fc7\u7a0b\u662f\u5f02\u6b65\u7684\uff0cRedis\u5b95\u673a\u65f6\u4f1a\u4e22\u59311\u79d2\u7684\u6570\u636e\u3002\u800c\u5982\u679cAOF\u6539\u4e3a\u540c\u6b65\u5199\u76d8\uff0c\u90a3\u4e48\u5199\u5165\u6027\u80fd\u4f1a\u4e0b\u964d\u3002\u53e6\u4e00\u4e2a\u573a\u666f\u662f\uff0c\u5982\u679c\u91c7\u7528\u4e3b\u4ece\u96c6\u7fa4\uff0c\u5982\u679c\u5199\u5165\u91cf\u6bd4\u8f83\u5927\uff0c\u4ece\u5e93\u540c\u6b65\u5b58\u5728\u5ef6\u8fdf\uff0c\u6b64\u65f6\u8fdb\u884c\u4e3b\u4ece\u5207\u6362\uff0c\u4e5f\u5b58\u5728\u4e22\u5931\u6570\u636e\u7684\u53ef\u80fd\uff08\u4ece\u5e93\u8fd8\u672a\u540c\u6b65\u5b8c\u6210\u4e3b\u5e93\u53d1\u6765\u7684\u6570\u636e\u5c31\u88ab\u63d0\u6210\u4e3b\u5e93\uff09\u3002\u603b\u7684\u6765\u8bf4\uff0cRedis\u4e0d\u4fdd\u8bc1\u4e25\u683c\u7684\u6570\u636e\u5b8c\u6574\u6027\u548c\u4e3b\u4ece\u5207\u6362\u65f6\u7684\u4e00\u81f4\u6027\u3002\u6211\u4eec\u5728\u4f7f\u7528Redis\u65f6\u9700\u8981\u6ce8\u610f\u3002<\/p>\n<p dir=\"auto\">b) \u800c\u91c7\u7528RabbitMQ\u548cKafka\u8fd9\u4e9b\u4e13\u4e1a\u7684\u961f\u5217\u4e2d\u95f4\u4ef6\u65f6\uff0c\u5c31\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u4e86\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u4e00\u822c\u662f\u90e8\u7f72\u4e00\u4e2a\u96c6\u7fa4\uff0c\u751f\u4ea7\u8005\u5728\u53d1\u5e03\u6d88\u606f\u65f6\uff0c\u961f\u5217\u4e2d\u95f4\u4ef6\u4e00\u822c\u4f1a\u91c7\u7528\u5199\u591a\u4e2a\u8282\u70b9+\u9884\u5199\u78c1\u76d8\u7684\u65b9\u5f0f\u4fdd\u8bc1\u6d88\u606f\u7684\u5b8c\u6574\u6027\uff0c\u5373\u4fbf\u5176\u4e2d\u4e00\u4e2a\u8282\u70b9\u6302\u4e86\uff0c\u4e5f\u80fd\u4fdd\u8bc1\u96c6\u7fa4\u7684\u6570\u636e\u4e0d\u4e22\u5931\u3002\u5f53\u7136\uff0c\u4e3a\u4e86\u505a\u5230\u8fd9\u4e9b\uff0c\u65b9\u6848\u80af\u5b9a\u6bd4Redis\u8bbe\u8ba1\u7684\u8981\u590d\u6742\uff08\u6bd5\u7adf\u662f\u4e13\u4eec\u9488\u5bf9\u961f\u5217\u573a\u666f\u8bbe\u8ba1\u7684\uff09\u3002<\/p>\n<p dir=\"auto\">\u7efc\u4e0a\uff0cRedis\u53ef\u4ee5\u7528\u4f5c\u961f\u5217\uff0c\u800c\u4e14\u6027\u80fd\u5f88\u9ad8\uff0c\u90e8\u7f72\u7ef4\u62a4\u4e5f\u5f88\u8f7b\u91cf\uff0c\u4f46\u7f3a\u70b9\u662f\u65e0\u6cd5\u4e25\u683c\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\uff08\u4e2a\u4eba\u8ba4\u4e3a\u8fd9\u5c31\u662f\u4e1a\u754c\u6709\u4e89\u8bae\u8981\u4e0d\u8981\u4f7f\u7528Redis\u5f53\u4f5c\u961f\u5217\u7684\u5730\u65b9\uff09\u3002\u800c\u4f7f\u7528\u4e13\u4e1a\u7684\u961f\u5217\u4e2d\u95f4\u4ef6\uff0c\u53ef\u4ee5\u4e25\u683c\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\uff0c\u4f46\u7f3a\u70b9\u662f\uff0c\u90e8\u7f72\u7ef4\u62a4\u6210\u672c\u9ad8\uff0c\u7528\u8d77\u6765\u6bd4\u8f83\u91cd\u3002<\/p>\n<p dir=\"auto\">\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u9009\u62e9\uff0c\u5982\u679c\u5bf9\u4e8e\u4e22\u6570\u636e\u4e0d\u654f\u611f\u7684\u4e1a\u52a1\uff0c\u4f8b\u5982\u53d1\u77ed\u4fe1\u3001\u53d1\u901a\u77e5\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u91c7\u7528Redis\u4f5c\u961f\u5217\u3002\u5982\u679c\u662f\u91d1\u878d\u76f8\u5173\u7684\u4e1a\u52a1\u573a\u666f\uff0c\u4f8b\u5982\u4ea4\u6613\u3001\u652f\u4ed8\u8fd9\u7c7b\uff0c\u5efa\u8bae\u8fd8\u662f\u4f7f\u7528\u4e13\u4e1a\u7684\u961f\u5217\u4e2d\u95f4\u4ef6\u3002<\/p>\n<h5 dir=\"auto\"><a id=\"user-content-\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u65b9\u5f0f\u5bf9\u6bd4\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F%E5%AF%B9%E6%AF%94\" aria-hidden=\"true\"><\/a>\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u65b9\u5f0f\u5bf9\u6bd4<\/h5>\n<p dir=\"auto\">\u5173\u4e8eRedis\u662f\u5426\u9002\u5408\u505a\u6d88\u606f\u961f\u5217\uff0c\u4e1a\u754c\u4e00\u76f4\u5b58\u5728\u4e89\u8bae\u3002\u5f88\u591a\u4eba\u8ba4\u4e3a\u4f7f\u7528\u6d88\u606f\u961f\u5217\u5c31\u5e94\u8be5\u91c7\u7528KafKa\uff0cRabbitMQ\u8fd9\u4e9b\u4e13\u95e8\u6ca1\u5b89\u5fc3\u6d88\u606f\u961f\u5217\u573a\u666f\u7684\u8f6f\u4ef6\uff0c\u800cRedis\u66f4\u9002\u5408\u505a\u7f13\u5b58\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u529f\u80fd\u548c\u9002\u7528\u573a\u666f<\/th>\n<th align=\"left\">\u57fa\u4e8eRedis<\/th>\n<th align=\"left\">\u57fa\u4e8eKafka\/RabbitMQ<\/th>\n<th align=\"left\">\u5907\u6ce8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">\u9002\u7528\u573a\u666f<\/td>\n<td align=\"left\">\u5bf9\u4e22\u6570\u636e\u4e0d\u654f\u611f\u7684\u4e1a\u52a1\uff0c\u5982\u53d1\u77ed\u4fe1\u548c\u901a\u77e5<\/td>\n<td align=\"left\">\u4e25\u683c\u6570\u636e\u5b8c\u6574\u7684\u5e94\u7528\uff0c\u91d1\u878d\u76f8\u5173\u4e1a\u52a1\u573a\u666f\uff0c\u652f\u4ed8\u548c\u4ea4\u6613<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5c5e\u6027<\/td>\n<td align=\"left\">\u8f7b\u91cf\u7ea7\uff0c\u90e8\u7f72\u548c\u7ef4\u62a4\u7b80\u5355\uff0c\u6027\u80fd\u9ad8<\/td>\n<td align=\"left\">\u91cd\u91cf\u7ea7<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6570\u636e\u5b8c\u6574\u6027<\/td>\n<td align=\"left\">\u4e0d\u4fdd\u8bc1\u4e25\u683c\u7684\u6570\u636e\u5b8c\u6574\u6027\u548c\u4e3b\u4ece\u5207\u6362\u7684\u4e00\u81f4\u6027<\/td>\n<td align=\"left\">\u90e8\u7f72\u96c6\u7fa4\uff0c\u591a\u7ed3\u70b9+\u9884\u5199\u78c1\u76d8\u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u91cd\u590d\u6d88\u606f\u5904\u7406<\/td>\n<td align=\"left\">\u751f\u4ea7\u8005\u81ea\u884c\u5b9e\u73b0\u5168\u5c40\u552f\u4e00ID<\/td>\n<td align=\"left\">STREAMs\u81ea\u884c\u751f\u6210\u5168\u5c40\u552f\u4e00ID<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6d88\u606f\u53ef\u9760\u6027<\/td>\n<td align=\"left\">\u9002\u7528BRPOPRPUSH<\/td>\n<td align=\"left\">\u4f7f\u7528PENDING List \u81ea\u52a8\u5b58\u7559\u6d88\u606f\uff0c\u4f7f\u7528XPENGDING\u67e5\u770b\uff0c\u4f7f\u7528XACK\u786e\u8ba4\u6d88\u606f<\/td>\n<td align=\"left\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 dir=\"auto\"><a id=\"user-content-\u5982\u4f55\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\u5373\u5982\u4f55\u5b66\u4e60c\u7684\u9762\u5411\u5bf9\u8c61\u601d\u60f3\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%A6%82%E4%BD%95%E5%AD%A6%E4%B9%A0%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E5%8D%B3%E5%A6%82%E4%BD%95%E5%AD%A6%E4%B9%A0c%E7%9A%84%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%80%9D%E6%83%B3\" aria-hidden=\"true\"><\/a>\u5982\u4f55\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f(\u5373\u5982\u4f55\u5b66\u4e60C++\u7684\u9762\u5411\u5bf9\u8c61\u601d\u60f3)<\/h3>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/franktea\">\u8be5\u5185\u5bb9\u6765\u81ea@franktea<\/a><\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u5927\u7279\u5f81\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%9A%84%E4%B8%89%E5%A4%A7%E7%89%B9%E5%BE%81\" aria-hidden=\"true\"><\/a>\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u5927\u7279\u5f81<\/h4>\n<p dir=\"auto\">\u6240\u6709\u7684\u4eba\u90fd\u77e5\u9053\uff0c\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u5927\u7279\u5f81\u662f\u5c01\u88c5\u7ee7\u627f\u591a\u6001\uff08\u8fd9\u91cc\u7684\u591a\u6001\u6307\u7684\u662f\u8fd0\u884c\u65f6\u591a\u6001\uff0c\u672c\u6587\u4e2d\u6240\u6709\u591a\u6001\u5747\u6307\u8fd0\u884c\u65f6\u591a\u6001\uff09\uff0c\u90a3\u4e48\u54ea\u4e2a\u7279\u5f81\u624d\u662f\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u7279\u5f81\u5462\uff1f<\/p>\n<p dir=\"auto\">\u5148\u8bf4\u5c01\u88c5\u3002\u5176\u5b9eC\u8bed\u8a00\u7684struct\u4e5f\u662f\u4e00\u79cd\u5c01\u88c5\uff0c\u6240\u4ee5\u5c01\u88c5\u5e76\u4e0d\u662f\u9762\u5411\u5bf9\u8c61\u6240\u72ec\u6709\u3002\u518d\u770b\u7ee7\u627f\uff0c\u7ee7\u627f\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u91cd\u7528\u4ee3\u7801\uff0c\u76f8\u5bf9\u9762\u5411\u8fc7\u7a0b\u6765\u8bf4\u662f\u4e00\u79cd\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5728\u9762\u5411\u5bf9\u8c61\u521a\u88ab\u53d1\u660e\u51fa\u6765\u4e0d\u4e45\u7684\u4e00\u6bb5\u65f6\u95f4\u91cc\uff0c\u7ee7\u627f\u88ab\u5f88\u591a\u4eba\u770b\u6210\u9762\u5411\u5bf9\u8c61\u6700\u5f3a\u5927\u7684\u7279\u5f81\u3002<\/p>\n<p dir=\"auto\">\u5230\u540e\u6765\uff0c\u4eba\u4eec\u53d1\u73b0\u9762\u5411\u5bf9\u8c61\u6700\u5f3a\u5927\u7684\u7279\u5f81\u662f\u591a\u6001\uff0c\u56e0\u4e3a\u4ee3\u7801\u4e0d\u4ec5\u4ec5\u662f\u9700\u8981\u91cd\u7528\uff0c\u6269\u5c55\u4e5f\u5f88\u91cd\u8981\u3002\u300c\u8bbe\u8ba1\u6a21\u5f0f\u300d\u4e2d\uff0c\u51e0\u4e4e\u6bcf\u79cd\u6a21\u5f0f\uff0c\u90fd\u662f\u7528\u591a\u6001\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<p dir=\"auto\">\u4e00\u4e2a\u95ee\u9898\uff1a\u53ea\u652f\u6301\u591a\u6001\uff0c\u4e0d\u652f\u6301\u7ee7\u627f\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u7b97\u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u5417\uff1f<\/p>\n<p dir=\"auto\">\u6211\u7684\u7b54\u6848\uff1a\u4e0d\u662f\u3002\u867d\u7136\u7ee7\u627f\u4e0d\u5982\u591a\u6001\u91cd\u8981\uff0c\u4f46\u662f\u5b83\u4e0d\u662f\u591a\u4f59\u7684\u3002\u591a\u6001\u5f80\u5f80\u662f\u914d\u5408\u7ee7\u627f\u624d\u66f4\u5f3a\u5927\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u7c7b\u7684\u8bbe\u8ba1\u4ee5\u53ca\u591a\u6001\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E7%B1%BB%E7%9A%84%E8%AE%BE%E8%AE%A1%E4%BB%A5%E5%8F%8A%E5%A4%9A%E6%80%81\" aria-hidden=\"true\"><\/a>\u7c7b\u7684\u8bbe\u8ba1\u4ee5\u53ca\u591a\u6001<\/h4>\n<p dir=\"auto\">\u7b2c\u4e00\u70b9\uff0c\u524d\u9762\u8bf4\u4e86\uff0c\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u662f\u591a\u6001\uff0c\u591a\u6001\u5c31\u662f\u4f7f\u7528\u865a\u51fd\u6570\uff0c\u5728\u81ea\u5df1\u8bbe\u8ba1\u7684\u7c7b\u4e2d\uff0c\u5c06\u54ea\u4e9b\u6210\u5458\u51fd\u6570\u5b9a\u4e49\u4e3a\u865a\u51fd\u6570\uff0c\u8fd9\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u95ee\u9898\u3002\u5bf9\u4e8e\u65b0\u624b\uff0c\u6211\u7684\u5efa\u8bae\u662f\uff1a\u5728\u641e\u6e05\u89c4\u5219\u4e4b\u524d\uff0c\u53ef\u4ee5\u5c06\u6240\u6709\u7684\u6210\u5458\u51fd\u6570\u90fd\u5b9a\u4e49\u4e3a\u865a\u51fd\u6570\u3002\uff08\u5176\u5b9e\u5728java\u8fd9\u6837\u7684\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6839\u672c\u4e0d\u9700\u8981\u7a0b\u5e8f\u5458\u81ea\u5df1\u53bb\u6307\u5b9a\u54ea\u4e2a\u6210\u5458\u51fd\u6570\u662fvirtual\uff0c\u4ece\u8bed\u6cd5\u4e0a\u6765\u8bf4\uff0c\u4efb\u4f55\u4e00\u4e2a\u975estatic\u975eprivate\u7684\u90fd\u662fvirtual\u3002\uff09<\/p>\n<p dir=\"auto\">\u5728\u865a\u51fd\u6570\u7684\u5b9a\u4e49\u4e0a\uff0c\u5148\u5c06\u6240\u6709\u80fd\u5b9a\u4e49\u6210\u865a\u51fd\u6570\u7684\u7684\u6210\u5458\u51fd\u6570\u5168\u90e8\u58f0\u660e\u4e3avirtual\uff0c\u7136\u540e\u518d\u5728\u4f7f\u7528\u4e2d\u6162\u6162\u505a\u51cf\u6cd5\uff0c\u6839\u636e\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u5c06\u591a\u4f59\u7684virtual\u53bb\u6389\u3002<\/p>\n<p dir=\"auto\">\u7b2c\u4e8c\u70b9\uff0c\u5728\u4f7f\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5c3d\u91cf\u4f7f\u7528\u7236\u7c7b\u6307\u9488\uff0c\u800c\u4e0d\u662f\u5b50\u7c7b\u6307\u9488\u3002100\u5206\u7684\u8bbe\u8ba1\u662f\u6c38\u8fdc\u4f7f\u7528\u7236\u7c7b\u6307\u9488\u3001\u6c38\u8fdc\u4e0d\u4f7f\u7528\u5b50\u7c7b\u6307\u9488\u3002\u7236\u7c7b\u6307\u9488\u5411\u5b50\u7c7b\u6307\u9488\u8f6c\u6362\u9700\u8981\u7528dynamic_cast\uff0c\u4e0d\u4f7f\u7528dynamic_cast\u7684\u8bbe\u8ba1\u5c31\u662f\u6700\u597d\u7684\u8bbe\u8ba1\u3002\u65b0\u624b\u53ef\u4ee5\u9075\u5faa\u8fd9\u4e2a\u539f\u5219\u3002<\/p>\n<p dir=\"auto\">\u5f53\u7136\uff0c\u5728\u4e00\u4e9b\u975e\u5e38\u590d\u6742\u7684\u7cfb\u7edf\u4e2d\uff0c\u65e0\u6cd5\u505a\u5230100\u5206\uff0c\u6709\u65f6\u5019\u8fd8\u662f\u9700\u8981\u5411\u4e0b\u8f6c\u6362\u6210\u5b50\u7c7b\u6307\u9488\uff0c\u8fd9\u6837\u7684\u8bbe\u8ba1\u80af\u5b9a\u662f\u6263\u5206\u7684\uff0c\u4f46\u662f\u5bf9\u4e8e\u590d\u6742\u7cfb\u7edf\u80af\u5b9a\u6709\u4e00\u4e2a\u5e73\u8861\u3002\u6211\u81ea\u5df1\u505a\u670d\u52a1\u5668\uff0c\u6240\u6709\u8bbe\u8ba1\u90fd\u53ef\u4ee5\u505a\u5230\u6c38\u8fdc\u4f7f\u7528\u7236\u7c7b\u6307\u9488\uff0c\u4f46\u662f\u5bf9\u4e8e\u590d\u6742\u7684\u50cf\u5ba2\u6237\u7aefunnreal\u4ee3\u7801\uff0c\u5411\u4e0b\u8f6c\u6362\u51e0\u4e4e\u4e0d\u53ef\u907f\u514d\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u865a\u51fd\u6570\u8868\u548c\u865a\u51fd\u6570\u6307\u9488\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%99%9A%E5%87%BD%E6%95%B0%E8%A1%A8%E5%92%8C%E8%99%9A%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88\" aria-hidden=\"true\"><\/a>\u865a\u51fd\u6570\u8868\u548c\u865a\u51fd\u6570\u6307\u9488<\/h4>\n<p dir=\"auto\">\u5173\u4e8e\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u6cd5\u77e5\u8bc6\uff0c\u6211\u552f\u4e00\u89c9\u5f97\u9700\u8981\u5f3a\u8c03\u7684\u5c31\u662f\u5bf9\u4e8evtable\u7684\u5b9e\u73b0\uff0c\u63a8\u8350\u5927\u5bb6\u7528\u5b9e\u9a8c\u7684\u65b9\u6cd5\uff0c\u4e00\u5b9a\u8981\u81ea\u5df1\u5199\u4ee3\u7801\u4eb2\u81ea\u64cd\u4f5c\u4e00\u904d\uff08\u6309\u7167\u968f\u4fbf\u4e00\u7bc7vtable\u539f\u7406\u7684\u6587\u7ae0\u52a8\u624b\u64cd\u4f5c\u4e00\u904d\u5373\u53ef\uff09\uff0c\u65e0\u8bba\u662f\u901a\u8fc7\u5355\u6b65\u8c03\u8bd5\u53bb\u67e5\u770bvtable\uff0c\u8fd8\u662f\u901a\u8fc7\u7f16\u8bd1\u5668\u7684\u5404\u79cd\u547d\u4ee4\u6765\u67e5\u770b\uff0c\u90fd\u8981\u81ea\u5df1\u4eb2\u81ea\u52a8\u624b\u64cd\u4f5c\u4e00\u4e0b\uff0c\u52a0\u6df1\u5370\u8c61\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u8865\u5145-1\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%A1%A5%E5%85%85-1\" aria-hidden=\"true\"><\/a>\u8865\u5145<\/h4>\n<p dir=\"auto\">gdb\u8c03\u8bd5\u8981\u70b9\uff1a 64\u4f4d, \u8bbe\u7f6e\u65ad\u70b9\uff0c\u6253\u5370\u865a\u8868\u3002<\/p>\n<div class=\"snippet-clipboard-content position-relative overflow-auto\">\n<pre><code>g++ \u591a\u7ee7\u627f\u6709\u865a\u51fd\u6570\u91cd\u5199.cpp -o \u591a\u7ee7\u627f\u6709\u865a\u51fd\u6570\u91cd\u5199 -m64 -g\r\nbreak 30\r\nset print pretty on\r\ninfo vtbl d\r\n<\/code><\/pre>\n<\/div>\n<h3 dir=\"auto\"><a id=\"user-content-\u4e00\u7bc7\u5f15\u6587\u4ecevtable\u5230\u8bbe\u8ba1\u6a21\u5f0f\u6211\u7684c\u9762\u5411\u5bf9\u8c61\u5b66\u4e60\u5fc3\u5f97\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E4%B8%80%E7%AF%87%E5%BC%95%E6%96%87%E4%BB%8Evtable%E5%88%B0%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E6%88%91%E7%9A%84c%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E5%AD%A6%E4%B9%A0%E5%BF%83%E5%BE%97\" aria-hidden=\"true\"><\/a>\u4e00\u7bc7\u5f15\u6587\uff1a\u4ecevtable\u5230\u8bbe\u8ba1\u6a21\u5f0f\u2014\u2014\u6211\u7684C++\u9762\u5411\u5bf9\u8c61\u5b66\u4e60\u5fc3\u5f97<\/h3>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/franktea\">\u8be5\u5185\u5bb9\u6765\u81ea@franktea<\/a><\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u524d\u8a00\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%89%8D%E8%A8%80\" aria-hidden=\"true\"><\/a>\u524d\u8a00<\/h4>\n<p dir=\"auto\">\u6309\u7167\u5f88\u591a\u6559\u7a0b\u7684\u5185\u5bb9\u5b89\u6392\uff0c\u5b66\u4e60C++\u8bed\u6cd5\u4ee5\u540e\u5f88\u5feb\u5c31\u4f1a\u8fdb\u5165\u5230\u9762\u5411\u5bf9\u8c61\u7684\u5b66\u4e60\uff0c\u5728\u521d\u5b66\u8005\u7684\u5fc3\u4e2d\uff0c\u9762\u5411\u5bf9\u8c61\u6709\u975e\u5e38\u91cd\u8981\u7684\u5730\u4f4d\u3002\u4f46\u662f\u5982\u4f55\u624d\u80fd\u5feb\u901f\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u3001\u591a\u4e45\u5b66\u4f1a\u9762\u5411\u5bf9\u8c61\u624d\u7b97\u6b63\u5e38\uff0c\u8fd9\u662f\u65b0\u624b\u5e38\u89c1\u7684\u95ee\u9898\u3002<\/p>\n<p dir=\"auto\">\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u6cd5\u4e66\u4e0a\u90fd\u6709\u8bf4\uff0cvtable\u7684\u539f\u7406\u4e5f\u6709\u975e\u5e38\u591a\u7684\u6587\u7ae0\u8fdb\u884c\u8bb2\u8ff0\uff0c\u8fd9\u4e9b\u4e1c\u897f\u518d\u4e00\u518d\u91cd\u590d\u6ca1\u6709\u610f\u4e49\uff0c\u6211\u60f3\u5199\u4e00\u4e9b\u6211\u81ea\u5df1\u5728\u5b66\u4e60\u8fc7\u7a0b\u4e2d\u7684\u5fc3\u5f97\u4f53\u9a8c\u3002<\/p>\n<p dir=\"auto\">\u5173\u4e8e\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u6cd5\u77e5\u8bc6\uff0c\u6211\u552f\u4e00\u89c9\u5f97\u9700\u8981\u5f3a\u8c03\u7684\u5c31\u662f\u5bf9\u4e8evtable\u7684\u5b9e\u73b0\uff0c\u63a8\u8350\u5927\u5bb6\u7528\u5b9e\u9a8c\u7684\u65b9\u6cd5\uff0c\u4e00\u5b9a\u8981\u81ea\u5df1\u5199\u4ee3\u7801\u4eb2\u81ea\u64cd\u4f5c\u4e00\u904d\uff08\u6309\u7167\u968f\u4fbf\u4e00\u7bc7vtable\u539f\u7406\u7684\u6587\u7ae0\u52a8\u624b\u64cd\u4f5c\u4e00\u904d\u5373\u53ef\uff09\uff0c\u65e0\u8bba\u662f\u901a\u8fc7\u5355\u6b65\u8c03\u8bd5\u53bb\u67e5\u770bvtable\uff0c\u8fd8\u662f\u901a\u8fc7\u7f16\u8bd1\u5668\u7684\u5404\u79cd\u547d\u4ee4\u6765\u67e5\u770b\uff0c\u90fd\u8981\u81ea\u5df1\u4eb2\u81ea\u52a8\u624b\u64cd\u4f5c\u4e00\u4e0b\uff0c\u52a0\u6df1\u5370\u8c61\u3002<\/p>\n<p dir=\"auto\">\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u6cd5\u98ce\u683c\u51fa\u73b0\u4ee5\u540e\uff0c\u65e0\u6570\u7684\u7a0b\u5e8f\u5458\u57fa\u4e8e\u8fd9\u4e9b\u7279\u6027\u5199\u51fa\u4e86\u5f88\u591a\u4ee3\u7801\uff0c\u5404\u663e\u795e\u901a\uff0c\u540e\u6765\u88ab\u603b\u7ed3\u63d0\u53d6\u51fa\u4e00\u4e9b\u53ef\u590d\u7528\u7684\u65b9\u6cd5\u8bba\uff0c\u53eb\u505a\u300c\u8bbe\u8ba1\u6a21\u5f0f\u300d\u3002\u8bbe\u8ba1\u6a21\u5f0f\u662f\u5b66\u4e60\u548c\u638c\u63e1\u9762\u5411\u5bf9\u8c61\u601d\u60f3\u7684\u91cd\u8981\u8bfe\u7a0b\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u4f55\u65f6\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\uff1f\u5982\u4f55\u5b66\u4e60\uff1f\u5728\u7406\u89e3\u8bbe\u8ba1\u6a21\u5f0f\u4e4b\u524d\u5e94\u8be5\u505a\u4ec0\u4e48\u3001\u80fd\u505a\u4ec0\u4e48\uff1f<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u5c01\u88c5\u7ee7\u627f\u8fd0\u884c\u65f6\u591a\u6001\u54ea\u4e2a\u624d\u662f\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u7279\u5f81\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%B0%81%E8%A3%85%E7%BB%A7%E6%89%BF%E8%BF%90%E8%A1%8C%E6%97%B6%E5%A4%9A%E6%80%81%E5%93%AA%E4%B8%AA%E6%89%8D%E6%98%AF%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%9C%80%E9%87%8D%E8%A6%81%E7%9A%84%E7%89%B9%E5%BE%81\" aria-hidden=\"true\"><\/a>\u5c01\u88c5\u3001\u7ee7\u627f\u3001\uff08\u8fd0\u884c\u65f6\uff09\u591a\u6001\uff0c\u54ea\u4e2a\u624d\u662f\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u7279\u5f81<\/h4>\n<p dir=\"auto\">\u6240\u6709\u7684\u4eba\u90fd\u77e5\u9053\uff0c\u9762\u5411\u5bf9\u8c61\u7684\u4e09\u5927\u7279\u5f81\u662f\u5c01\u88c5\u7ee7\u627f\u591a\u6001\uff08\u8fd9\u91cc\u7684\u591a\u6001\u6307\u7684\u662f\u8fd0\u884c\u65f6\u591a\u6001\uff0c\u672c\u6587\u4e2d\u6240\u6709\u591a\u6001\u5747\u6307\u8fd0\u884c\u65f6\u591a\u6001\uff09\uff0c\u90a3\u4e48\u54ea\u4e2a\u7279\u5f81\u624d\u662f\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u7279\u5f81\u5462\uff1f<\/p>\n<p dir=\"auto\">\u5148\u8bf4\u5c01\u88c5\u3002\u5176\u5b9eC\u8bed\u8a00\u7684struct\u4e5f\u662f\u4e00\u79cd\u5c01\u88c5\uff0c\u6240\u4ee5\u5c01\u88c5\u5e76\u4e0d\u662f\u9762\u5411\u5bf9\u8c61\u6240\u72ec\u6709\u3002\u518d\u770b\u7ee7\u627f\uff0c\u7ee7\u627f\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u91cd\u7528\u4ee3\u7801\uff0c\u76f8\u5bf9\u9762\u5411\u8fc7\u7a0b\u6765\u8bf4\u662f\u4e00\u79cd\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5728\u9762\u5411\u5bf9\u8c61\u521a\u88ab\u53d1\u660e\u51fa\u6765\u4e0d\u4e45\u7684\u4e00\u6bb5\u65f6\u95f4\u91cc\uff0c\u7ee7\u627f\u88ab\u5f88\u591a\u4eba\u770b\u6210\u9762\u5411\u5bf9\u8c61\u6700\u5f3a\u5927\u7684\u7279\u5f81\u3002<\/p>\n<p dir=\"auto\">\u5230\u540e\u6765\uff0c\u4eba\u4eec\u53d1\u73b0\u9762\u5411\u5bf9\u8c61\u6700\u5f3a\u5927\u7684\u7279\u5f81\u662f\u591a\u6001\uff0c\u56e0\u4e3a\u4ee3\u7801\u4e0d\u4ec5\u4ec5\u662f\u9700\u8981\u91cd\u7528\uff0c\u6269\u5c55\u4e5f\u5f88\u91cd\u8981\u3002\u300c\u8bbe\u8ba1\u6a21\u5f0f\u300d\u4e2d\uff0c\u51e0\u4e4e\u6bcf\u79cd\u6a21\u5f0f\uff0c\u90fd\u662f\u7528\u591a\u6001\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<p dir=\"auto\">\u4e00\u4e2a\u95ee\u9898\uff1a\u53ea\u652f\u6301\u591a\u6001\uff0c\u4e0d\u652f\u6301\u7ee7\u627f\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u7b97\u662f\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u5417\uff1f<\/p>\n<p dir=\"auto\">\u6211\u7684\u7b54\u6848\uff1a\u4e0d\u662f\u3002\u867d\u7136\u7ee7\u627f\u4e0d\u5982\u591a\u6001\u91cd\u8981\uff0c\u4f46\u662f\u5b83\u4e0d\u662f\u591a\u4f59\u7684\u3002\u591a\u6001\u5f80\u5f80\u662f\u914d\u5408\u7ee7\u627f\u624d\u66f4\u5f3a\u5927\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u8bbe\u8ba1\u6a21\u5f0f\u7684\u610f\u4e49\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%84%8F%E4%B9%89\" aria-hidden=\"true\"><\/a>\u8bbe\u8ba1\u6a21\u5f0f\u7684\u610f\u4e49<\/h4>\n<p dir=\"auto\">\u8bbe\u8ba1\u6a21\u5f0f\u5bf9\u4e8e\u5982\u4f55\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3\u89e3\u51b3\u8f6f\u4ef6\u4e2d\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u95ee\u9898\u63d0\u4f9b\u4e86\u4e00\u4e9b\u53ef\u91cd\u7528\u7684\u601d\u8def\uff0c\u5b83\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u610f\u4e49\uff0c\u5c31\u662f\u4e3a\u6bcf\u79cd\u8bbe\u8ba1\u601d\u8def\u90fd\u53d6\u4e86\u540d\u5b57\uff0c\u4fbf\u4e8e\u7a0b\u5e8f\u5458\u4e4b\u95f4\u7684\u4ea4\u6d41\u3002<\/p>\n<p dir=\"auto\">\u6709\u4e9b\u4eba\u5728\u8bbe\u8ba1\u7c7b\u7684\u540d\u5b57\u7684\u65f6\u5019\u5c31\u5305\u542b\u4e86\u4f7f\u7528\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u6bd4\u5982\u4e00\u4e2a\u4f7f\u7528\u4e86adapter\u6a21\u5f0f\u7684\u7c7b\u540d\u5b57\u53ebxxxAdapter\uff1bxxxFactory\u4e00\u770b\u5c31\u77e5\u9053\u5b83\u4f7f\u7528\u4e86factory\u6a21\u5f0f\uff0c\u7ed9\u5176\u5b83\u4f7f\u7528\u548c\u7ef4\u62a4\u8fd9\u4e9b\u4ee3\u7801\u7684\u4eba\u8282\u7701\u4e86\u5927\u91cf\u7684\u65f6\u95f4\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u4f55\u65f6\u5f00\u59cb\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E4%BD%95%E6%97%B6%E5%BC%80%E5%A7%8B%E5%AD%A6%E4%B9%A0%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F\" aria-hidden=\"true\"><\/a>\u4f55\u65f6\u5f00\u59cb\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f<\/h4>\n<p dir=\"auto\">\u77e5\u4e4e\u4e0a\u89c1\u8fc7\u4e00\u4e2a\u95ee\u9898\uff1a\u300e\u4f60\u60f3\u5bf9\u521a\u6bd5\u4e1a\u7684\u4eba\u8bf4\u4e9b\u4ec0\u4e48\u300f\uff0c\u8fd9\u4e2a\u95ee\u9898\u5c31\u662f\u4e00\u4e2a\u521a\u8e0f\u5165\u793e\u4f1a\u7684\u5c0f\u9c9c\u8089\uff0c\u5411\u5728\u793e\u4f1a\u4e0a\u6478\u722c\u6eda\u6253\u591a\u5e74\u7684\u4eba\u53d6\u7ecf\uff0c\u60f3\u83b7\u5f97\u4e00\u4e9b\u751f\u5b58\u95ef\u5173\u7684\u91d1\u53e5\u5b9d\u5178\uff0c\u4ece\u800c\u8ba9\u81ea\u5df1\u5c11\u8e29\u5751\u3002<\/p>\n<p dir=\"auto\">\u8fd9\u6837\u7684\u95ee\u9898\u7684\u7b54\u6848\u6709\u610f\u4e49\u5417\uff1f\u6709\u4e00\u4e9b\u662f\u6709\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u7406\u89e3\uff0c\u4f46\u662f\u5f88\u591a\u662f\u8981\u7ed3\u5408\u81ea\u5df1\u8fc7\u53bb\u7684\u7ecf\u9a8c\u6559\u8bad\u624d\u80fd\u6709\u4f53\u4f1a\u7684\uff0c\u77e5\u9053\u5f97\u65e9\u4e5f\u6ca1\u6709\u4ec0\u4e48\u6536\u83b7\u3002<\/p>\n<p dir=\"auto\">\u5982\u679c\u9762\u5411\u5bf9\u8c61\u7684\u521d\u5b66\u8005\u4e5f\u63d0\u95ee\uff1a\u300c\u4f60\u60f3\u5bf9\u521a\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7684\u4eba\u8bf4\u4ec0\u4e48\uff1f\u300d\uff0c\u7b54\u6848\u5c31\u5728\u8bbe\u8ba1\u6a21\u5f0f\u8fd9\u672c\u4e66\u4e2d\u3002<\/p>\n<p dir=\"auto\">\u6240\u4ee5\u4f55\u65f6\u5f00\u59cb\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\u5462\uff1f\u6211\u7684\u7b54\u6848\u662f\u4efb\u4f55\u65f6\u5019\u90fd\u53ef\u4ee5\u3002\u4f46\u662f\u552f\u4e00\u8981\u6ce8\u610f\u7684\u5c31\u662f\uff0c\u4e0d\u8981\u5f3a\u8feb\u81ea\u5df1\u53bb\u7406\u89e3\uff0c\u8bbe\u8ba1\u6a21\u5f0f\u7684\u4e66\u53ef\u4ee5\u6446\u5728\u90a3\u91cc\uff0c\u60f3\u770b\u5c31\u770b\u4e00\u4e0b\uff0c\u80fd\u7406\u89e3\u591a\u5c11\u5c31\u7406\u89e3\u591a\u5c11\u3002\u4f46\u662f\u8d8a\u65e9\u770b\u8bbe\u8ba1\u6a21\u5f0f\u8fd9\u672c\u4e66\uff0c\u5171\u9e23\u5c31\u8d8a\u5c11\uff0c\u56e0\u4e3a\u5171\u9e23\u662f\u8981\u7ed3\u5408\u81ea\u5df1\u5199\u9762\u5411\u5bf9\u8c61\u4ee3\u7801\u7684\u7ecf\u9a8c\u7684\u3002<\/p>\n<p dir=\"auto\">\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u51e0\u5e74\u4ee5\u540e\u518d\u770b\u8bbe\u8ba1\u6a21\u5f0f\u662f\u5426\u53ef\u4ee5\u884c\uff1f<\/p>\n<p dir=\"auto\">\u6211\u89c9\u5f97\u53ef\u884c\uff0c\u7ed3\u5408\u81ea\u5df1\u51e0\u5e74\u4e4b\u5185\u5728\u5b66\u4e60\u5404\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u5e93\u548c\u81ea\u5df1\u5199\u4ee3\u7801\u7684\u7ecf\u9a8c\uff0c\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\u4f1a\u5f88\u5feb\u3002<\/p>\n<p dir=\"auto\">\u6c38\u8fdc\u4e0d\u5b66\u8bbe\u8ba1\u6a21\u5f0f\u884c\u4e0d\u884c\uff1f<\/p>\n<p dir=\"auto\">\u6211\u89c9\u5f97\u4e0d\u884c\uff0c\u6211\u524d\u9762\u63d0\u5230\u4e86\uff0c\u8bbe\u8ba1\u6a21\u5f0f\u4e0d\u4ec5\u4ec5\u662f\u603b\u7ed3\u601d\u60f3\uff0c\u601d\u60f3\u53ef\u4ee5\u901a\u8fc7\u6a21\u4eff\u73b0\u6709\u7684\u5e93\u6765\u5b66\u4e60\uff0c\u4f46\u662f\u8bbe\u8ba1\u6a21\u5f0f\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u4f5c\u7528\u662f\u7ed9\u6a21\u5f0f\u547d\u540d\uff0c\u547d\u540d\u53ef\u4ee5\u66f4\u597d\u5730\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u5458\u6c9f\u901a\u4ea4\u6d41\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u5982\u4f55\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f\u5373\u5982\u4f55\u5b66\u4e60c\u7684\u9762\u5411\u5bf9\u8c61\u601d\u60f3-1\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%A6%82%E4%BD%95%E5%AD%A6%E4%B9%A0%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E5%8D%B3%E5%A6%82%E4%BD%95%E5%AD%A6%E4%B9%A0c%E7%9A%84%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%80%9D%E6%83%B3-1\" aria-hidden=\"true\"><\/a>\u5982\u4f55\u5b66\u4e60\u8bbe\u8ba1\u6a21\u5f0f(\u5373\u5982\u4f55\u5b66\u4e60C++\u7684\u9762\u5411\u5bf9\u8c61\u601d\u60f3)<\/h4>\n<p dir=\"auto\">\u9664\u4e86\u5b66\u4e60C++\u8bed\u6cd5\uff0c\u8fd8\u9700\u8981\u5b66\u4e60\u4e00\u4e0bUML\u7c7b\u56fe\uff0c\u4e0d\u4f1a\u7684\u81ea\u5df1\u53bb\u641c\uff0cUML\u6709\u597d\u51e0\u79cd\u56fe\uff0c\u5176\u4e2d\u7c7b\u56fe\u3001\u72b6\u6001\u56fe\u3001\u5e8f\u5217\u56fe\u6700\u4e3a\u5e38\u7528\uff0c\u5b66\u8fd93\u79cd\u5373\u53ef\u3002<\/p>\n<p dir=\"auto\">\u5728C++\u4e2d\u53ef\u4ee5\u901a\u8fc7\u5b66Qt\u5e93\u6765\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u3002Qt\u9664\u4e86\u53ef\u4ee5\u7528\u6765\u5199\u8de8\u5e73\u53f0\u7684UI\uff0c\u8fd8\u53ef\u4ee5\u5199\u4e00\u4e9b\u7b80\u5355\u7684\u7f51\u7edc\u7a0b\u5e8f\uff0c\u5728\u5b66\u6821\u91cc\u53ef\u4ee5\u7528\u6765\u505a\u5404\u79cd\u5927\u4f5c\u4e1a\uff0c\u65e0\u8bba\u662f\u5b66\u751f\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf\u3001\u56fe\u4e66\u7ba1\u7406\u7cfb\u7edf\u3001\u8db3\u7403\u4ff1\u4e50\u90e8\uff0c\u7b49\u7b49\uff0c\u7528Qt\u90fd\u53ef\u4ee5\u5f88\u597d\u5730\u5b8c\u6210\u3002\u6211\u5b66Qt\u7528\u7684\u662f\u8fd9\u672c\u4e66\uff1a&lt;&lt;Qt Creator \u5feb\u901f\u5165\u95e8 \u970d\u4e9a\u98de\u8457&gt;&gt;<\/p>\n<p dir=\"auto\">Qt\u91cc\u9762\u672c\u8eab\u5c31\u7528\u4e86\u5f88\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u4ece\u5b83\u7684\u7c7b\u91cc\u9762\u7ee7\u627f\u4e00\u4e2a\u5b50\u7c7b\uff0c\u8986\u76d6\u4e00\u4e2a\u6216\u51e0\u4e2a\u865a\u51fd\u6570\uff0c\u5c31\u53ef\u4ee5\u5c06\u81ea\u5df1\u7684\u7c7b\u878d\u5165\u5230Qt\u7684\u4f53\u7cfb\u4e2d\u3002\u5176\u5b9e\u8fd9\u5c31\u662f\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7684\u7b2c\u4e00\u6b65\uff0c\u4e5f\u662f\u6700\u597d\u7684\u5f00\u59cb\uff0c\u4e0d\u5403\u732a\u8089\u3001\u5148\u770b\u732a\u8dd1\uff0c\u4ece\u5b83\u7684\u7c7b\u7ee7\u627f\u591a\u4e86\uff0c\u81ea\u5df1\u4e5f\u4f1a\u6162\u6162\u7406\u89e3\u5982\u4f55\u4ece\u81ea\u5df1\u5199\u7684\u7c7b\u7ee7\u627f\u3002<\/p>\n<p dir=\"auto\">\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u6709\u4ec0\u4e48\u51cf\u5c11\u5f2f\u8def\u53c8\u80fd\u52a0\u901f\u7406\u89e3\u7684\u5957\u8def\u5462\uff1f\u6839\u636e\u6211\u81ea\u5df1\u7684\u7ecf\u9a8c\u603b\u7ed3\uff0c\u5bf9\u4e8e\u65b0\u624b\u6211\u81f3\u5c11\u53ef\u4ee5\u8bf4\u4e24\u70b9\u3002<\/p>\n<p dir=\"auto\">\u7b2c\u4e00\u70b9\uff0c\u524d\u9762\u8bf4\u4e86\uff0c\u9762\u5411\u5bf9\u8c61\u6700\u91cd\u8981\u7684\u662f\u591a\u6001\uff0c\u591a\u6001\u5c31\u662f\u4f7f\u7528\u865a\u51fd\u6570\uff0c\u5728\u81ea\u5df1\u8bbe\u8ba1\u7684\u7c7b\u4e2d\uff0c\u5c06\u54ea\u4e9b\u6210\u5458\u51fd\u6570\u5b9a\u4e49\u4e3a\u865a\u51fd\u6570\uff0c\u8fd9\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u95ee\u9898\u3002\u5bf9\u4e8e\u65b0\u624b\uff0c\u6211\u7684\u5efa\u8bae\u662f\uff1a\u5728\u641e\u6e05\u89c4\u5219\u4e4b\u524d\uff0c\u53ef\u4ee5\u5c06\u6240\u6709\u7684\u6210\u5458\u51fd\u6570\u90fd\u5b9a\u4e49\u4e3a\u865a\u51fd\u6570\u3002\uff08\u5176\u5b9e\u5728java\u8fd9\u6837\u7684\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u6839\u672c\u4e0d\u9700\u8981\u7a0b\u5e8f\u5458\u81ea\u5df1\u53bb\u6307\u5b9a\u54ea\u4e2a\u6210\u5458\u51fd\u6570\u662fvirtual\uff0c\u4ece\u8bed\u6cd5\u4e0a\u6765\u8bf4\uff0c\u4efb\u4f55\u4e00\u4e2a\u975estatic\u975eprivate\u7684\u90fd\u662fvirtual\u3002\uff09<\/p>\n<p dir=\"auto\">\u5728\u865a\u51fd\u6570\u7684\u5b9a\u4e49\u4e0a\uff0c\u5148\u5c06\u6240\u6709\u80fd\u5b9a\u4e49\u6210\u865a\u51fd\u6570\u7684\u7684\u6210\u5458\u51fd\u6570\u5168\u90e8\u58f0\u660e\u4e3avirtual\uff0c\u7136\u540e\u518d\u5728\u4f7f\u7528\u4e2d\u6162\u6162\u505a\u51cf\u6cd5\uff0c\u6839\u636e\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u5c06\u591a\u4f59\u7684virtual\u53bb\u6389\u3002<\/p>\n<p dir=\"auto\">\u7b2c\u4e8c\u70b9\uff0c\u5728\u4f7f\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5c3d\u91cf\u4f7f\u7528\u7236\u7c7b\u6307\u9488\uff0c\u800c\u4e0d\u662f\u5b50\u7c7b\u6307\u9488\u3002100\u5206\u7684\u8bbe\u8ba1\u662f\u6c38\u8fdc\u4f7f\u7528\u7236\u7c7b\u6307\u9488\u3001\u6c38\u8fdc\u4e0d\u4f7f\u7528\u5b50\u7c7b\u6307\u9488\u3002\u7236\u7c7b\u6307\u9488\u5411\u5b50\u7c7b\u6307\u9488\u8f6c\u6362\u9700\u8981\u7528dynamic_cast\uff0c\u4e0d\u4f7f\u7528dynamic_cast\u7684\u8bbe\u8ba1\u5c31\u662f\u6700\u597d\u7684\u8bbe\u8ba1\u3002\u65b0\u624b\u53ef\u4ee5\u9075\u5faa\u8fd9\u4e2a\u539f\u5219\u3002<\/p>\n<p dir=\"auto\">\u5f53\u7136\uff0c\u5728\u4e00\u4e9b\u975e\u5e38\u590d\u6742\u7684\u7cfb\u7edf\u4e2d\uff0c\u65e0\u6cd5\u505a\u5230100\u5206\uff0c\u6709\u65f6\u5019\u8fd8\u662f\u9700\u8981\u5411\u4e0b\u8f6c\u6362\u6210\u5b50\u7c7b\u6307\u9488\uff0c\u8fd9\u6837\u7684\u8bbe\u8ba1\u80af\u5b9a\u662f\u6263\u5206\u7684\uff0c\u4f46\u662f\u5bf9\u4e8e\u590d\u6742\u7cfb\u7edf\u80af\u5b9a\u6709\u4e00\u4e2a\u5e73\u8861\u3002\u6211\u81ea\u5df1\u505a\u670d\u52a1\u5668\uff0c\u6240\u6709\u8bbe\u8ba1\u90fd\u53ef\u4ee5\u505a\u5230\u6c38\u8fdc\u4f7f\u7528\u7236\u7c7b\u6307\u9488\uff0c\u4f46\u662f\u5bf9\u4e8e\u590d\u6742\u7684\u50cf\u5ba2\u6237\u7aefunnreal\u4ee3\u7801\uff0c\u5411\u4e0b\u8f6c\u6362\u51e0\u4e4e\u4e0d\u53ef\u907f\u514d\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u591a\u4e45\u5b66\u4f1a\u8bbe\u8ba1\u6a21\u5f0f\u624d\u7b97\u4f18\u79c0\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%A4%9A%E4%B9%85%E5%AD%A6%E4%BC%9A%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E6%89%8D%E7%AE%97%E4%BC%98%E7%A7%80\" aria-hidden=\"true\"><\/a>\u591a\u4e45\u5b66\u4f1a\u8bbe\u8ba1\u6a21\u5f0f\u624d\u7b97\u4f18\u79c0<\/h4>\n<p dir=\"auto\">\u521d\u5b66\u8005\u90fd\u5f88\u6025\u4e8e\u6c42\u6210\uff0c\u5e0c\u671b\u4e00\u5929\u5c31\u80fd\u5b66\u4f1a\u3002\u4f46\u662f\u4ece\u53e6\u4e00\u4e2a\u89d2\u5ea6\u6765\u8bf4\uff0c\u4e00\u5929\u90fd\u80fd\u5b66\u4f1a\u7684\u4e1c\u897f\uff0c\u80af\u5b9a\u4e0d\u662f\u4ec0\u4e48\u6709\u4ef7\u503c\u7684\u4e1c\u897f\u3002<\/p>\n<p dir=\"auto\">\u6211\u5927\u6982\u7528\u4e864\u5e74\u5de6\u53f3\u7684\u65f6\u95f4\uff0c\u7406\u89e3\u4e86\u9762\u5411\u5bf9\u8c61\u3002\u4ece\u5927\u4e00\u5f00\u59cb\u5b66\u4e60C++\uff0c\u5230\u5927\u56db\u6bd5\u4e1a\u5de5\u4f5c\u4ee5\u540e\u4e00\u5e74\u5185\u8bbe\u8ba1\u51fa\u6765\u4e86\u4e00\u4e2a\u603b\u5171\u6709\u4e00\u5343\u591a\u4e2a\u7c7b\u7684\u7cfb\u7edf\uff0c\u53ef\u4ee5\u6309\u7167\u9700\u6c42\u65e0\u9650\u6269\u5c55\u3002\u6211\u73b0\u5728\u53ef\u4ee5\u8bbe\u8ba1\u4efb\u610f\u591a\u4e2a\u7c7b\u7684\u7cfb\u7edf\u3002<\/p>\n<p dir=\"auto\">\u6211\u76f8\u4fe1\u5f88\u591a\u4eba\u6bd4\u6211\u66f4\u4f18\u79c0\uff0c\u4f46\u662f\u6211\u66f4\u76f8\u4fe1\u6211\u81ea\u5df1\u7684\u65b9\u6cd5\uff0c\u6211\u7684\u5b66\u4e60\u65b9\u6cd5\u5176\u5b9e\u5c31\u662f\u4e0d\u7ed9\u81ea\u5df1\u8bbe\u7f6e\u65f6\u95f4\u671f\u9650\uff0c\u76f2\u4eba\u6478\u8c61\uff0c\u4eca\u5929\u6478\u8fd9\u91cc\u660e\u5929\u6478\u90a3\u91cc\uff0c\u65f6\u95f4\u957f\u4e86\u603b\u4f1a\u77e5\u9053\u5927\u8c61\u7684\u5168\u8c8c\u3002<\/p>\n<p dir=\"auto\">\u6211\u662f\u6253\u7b97\u7528\u51e0\u5341\u5e74\u7684\u65f6\u95f4\u4ece\u4e8b\u7f16\u7a0b\u7684\u5de5\u4f5c\uff0c\u5230\u5e95\u662f\u4e00\u5929\u7406\u89e3\u8fd8\u662f\u51e0\u5e74\u7406\u89e3\uff0c\u5bf9\u6211\u6765\u8bf4\u5e76\u6ca1\u6709\u533a\u522b\u3002\u81f3\u4e8e\u505a\u9898\u3001\u8003\u8bd5\u3001\u5de5\u4f5c\u7b49\u7b49\uff0c\u4e0d\u7528\u7406\u89e3\u4e00\u6837\u53ef\u4ee5\u5b8c\u6210\uff0c\u6309\u7167\u73b0\u6709\u7684\u7cfb\u7edf\u6a21\u4eff\u5373\u53ef\u3002<\/p>\n<p dir=\"auto\">\u6211\u5f88\u6e05\u695a\u5730\u8bb0\u5f97\uff0c\u6211\u7b2c\u4e00\u6b21\u4f53\u4f1a\u5230\u9762\u5411\u5bf9\u8c61\u7684\u610f\u4e49\uff0c\u662f\u6a21\u4effMFC\u7684\u4e00\u4e2a\u673a\u5236\u3002MFC\u572890\u5e74\u4ee3\u7684\u65f6\u5019\u5c31\u505a\u5230\u4e86\u53ef\u4ee5\u7528\u5b57\u7b26\u4e32\u6765\u52a8\u6001\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff08C++\u6ca1\u6709\u53cd\u5c04\u673a\u5236\u8fd9\u5728\u8bed\u6cd5\u5c42\u9762\u662f\u65e0\u6cd5\u505a\u5230\u7684\uff09\uff0cMFC\u7528\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u5c06\u6240\u6709\u7684\u7c7b\u7684\u540d\u5b57\u548c\u5176\u6784\u9020\u51fd\u6570\u653e\u5728\u4e00\u4e2a\u5168\u5c40\u7684\u94fe\u8868\u4e2d\uff0c\u901a\u8fc7\u5b57\u7b26\u4e32\u5728\u94fe\u8868\u4e2d\u53bb\u67e5\u627e\u5bf9\u5e94\u7684\u6784\u9020\u51fd\u6570\uff0c\u4ece\u800c\u8c03\u7528\u8be5\u6784\u9020\u51fd\u6570new\u51fa\u5bf9\u5e94\u7684\u5bf9\u8c61\u3002<\/p>\n<p dir=\"auto\">\u9700\u8981\u6dfb\u52a0\u65b0\u7684\u529f\u80fd\u7684\u65f6\u5019\uff0c\u53ea\u8981\u65b0\u6dfb\u52a0\u4e00\u4e2a.h\u4e00\u4e2a.cpp\uff0c\u5728\u4e24\u4e2a\u6587\u4ef6\u4e2d\u5b9e\u73b0\u4e00\u4e2a\u5b50\u7c7b\u7684\u4ee3\u7801\uff0c\u5e76\u8c03\u7528\u5b8f\u5c06\u8be5\u7c7b\u7684\u6784\u9020\u51fd\u6570\u6dfb\u52a0\u5230\u5168\u5c40\u94fe\u8868\u4e2d\u3002<\/p>\n<p dir=\"auto\">\u901a\u8fc7\u6dfb\u52a0\u65b0\u6587\u4ef6\uff08\u4e00\u4e2a.h\u548c\u4e00\u4e2a.cpp\uff09\u7684\u65b9\u6cd5\uff0c\u4e0d\u7528\u4fee\u6539\u4e4b\u524d\u7684\u4efb\u4f55\u4ee3\u7801\uff0c\u5c31\u6269\u5c55\u4e86\u7a0b\u5e8f\u7684\u529f\u80fd\uff0c\u8fd9\u5c31\u662f\u9762\u5411\u5bf9\u8c61\u7684\u610f\u4e49\u4e4b\u4e00\u3002<\/p>\n<p dir=\"auto\">\u540e\u6765\u6211\u5728\u9e45\u5382\u505a\u670d\u52a1\u5668\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u6211\u4e00\u76f4\u4f7f\u7528\uff0c\u53ea\u662f\u5c06\u94fe\u8868\u6539\u6210\u4e86map\u6216unordered_map\u3002\u4ee5\u540e\u5982\u679c\u6211\u627e\u5230\u5408\u9002\u7684\u4f8b\u5b50\uff0c\u6211\u60f3\u901a\u8fc7\u4f8b\u5b50\u8bf4\u660e\u6b64\u601d\u60f3\u7684\u5e94\u7528\uff0c\u4f5c\u4e3a\u9762\u5411\u5bf9\u8c61\u601d\u60f3\u7406\u89e3\u7684\u5165\u95e8\u7ea7\u7d20\u6750\uff0c\u6211\u89c9\u5f97\u633a\u597d\u7684\uff0c\u5f53\u7136\uff0c\u90a3\u5c31\u662f\u53e6\u5916\u4e00\u7bc7\u6587\u7ae0\u4e86\u3002<\/p>\n<h4 dir=\"auto\"><a id=\"user-content-\u603b\u7ed3\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E6%80%BB%E7%BB%93\" aria-hidden=\"true\"><\/a>\u603b\u7ed3<\/h4>\n<p dir=\"auto\">\u8bbe\u8ba1\u6a21\u5f0f\u662f\u4e00\u4e9b\u65b9\u6cd5\u8bba\uff0c\u81ea\u5df1\u901a\u8fc7\u5b66\u4e60\u4f18\u79c0\u7684C++\u6846\u67b6\uff08\u5982Qt\uff09\u6162\u6162\u53bb\u4f53\u4f1a\u548c\u5e94\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6700\u7ec8\u53ef\u4ee5\u6162\u6162\u7406\u89e3\u3002<\/p>\n<p dir=\"auto\">\u4e0d\u8981\u523b\u610f\u6025\u4e8e\u6c42\u6210\uff0c\u4eba\u751f\u5f88\u957f\uff0c\u6bcf\u4e00\u6b65\u90fd\u6709\u5b83\u7684\u610f\u4e49\uff0c\u8d70\u8fc7\u7684\u8def\u54ea\u6015\u662f\u5f2f\u8def\uff0c\u90fd\u6709\u5b83\u7684\u610f\u4e49\u3002<\/p>\n<p dir=\"auto\">\u5728\u7406\u89e3\u4e4b\u524d\uff0c\u6ce8\u91cd\u4e8e\u6a21\u4eff\uff0c\u5373\u4f7f\u4e0d\u7406\u89e3\uff0c\u9760\u6a21\u4eff\u5df2\u7ecf\u80fd\u89e3\u51b3\u5f88\u591a\u95ee\u9898\u3002<\/p>\n<p dir=\"auto\">\u5982\u679c\u786c\u8981\u95ee\u6377\u5f84\u662f\u4ec0\u4e48\uff0c\u6211\u7684\u7b54\u6848\u5c31\u662f\u6293\u7d27\u65f6\u95f4\u591a\u5199\u4ee3\u7801\uff0c\u5199\u4e86\u51e0\u4e07\u884c\u4ee3\u7801\u5c31\u6162\u6162\u7406\u89e3\u4e86\u3002\u5982\u679c\u4f60\u4e0d\u80fd\u6539\u53d8\u51e0\u4e07\u884c\u8fd9\u4e2a\u6570\u5b57\uff0c\u90a3\u5c31\u53bb\u6539\u53d8\u79ef\u7d2f\u51e0\u4e07\u884c\u4ee3\u7801\u7684\u65f6\u95f4\u3002\u6bd4\u5982\u8bf4\u4ece3\u5e74\u7f29\u77ed\u52302\u5e74\uff0c\u8fd9\u5b8c\u5168\u662f\u53ef\u80fd\u7684\u3002<\/p>\n<p dir=\"auto\">\u6211\u975e\u5e38\u8ba8\u538c\u5199\u957f\u6587\uff0c\u8fd9\u7bc7\u6587\u7ae0\u5728\u6ca1\u6709\u4efb\u4f55\u4ee3\u7801\u51d1\u5b57\u6570\u7684\u60c5\u51b5\u4e0b\u8fd8\u662f\u8d85\u8fc7\u4e863000\u5b57\uff0c\u4e5f\u662f\u6e90\u4e8e\u6211\u5bf9\u9762\u5411\u5bf9\u8c61\u601d\u60f3\u7684\u70ed\u7231\uff0c\u5b83\u5e2e\u6211\u89e3\u51b3\u4e86\u5f88\u591a\u95ee\u9898\uff0c\u6211\u73b0\u5728\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3\u6765\u5199\u4ee3\u7801\uff0c\u5df2\u7ecf\u6210\u4e86\u4e00\u4ef6\u5f88\u81ea\u7136\u7684\u4e8b\u60c5\u3002<\/p>\n<p dir=\"auto\">\u5176\u5b9e\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3\u5728C++\u4e2d\u5e76\u4e0d\u662f\u4e3b\u6d41\uff0c\u81ea\u4ece90\u5e74\u4ee3STL\u88ab\u4f5c\u4e3a\u6807\u51c6\u5e93\u7eb3\u5165C++\u90a3\u4e00\u523b\u8d77\uff0c\u6cdb\u578b\u7f16\u7a0b\u5728C++\u91cc\u9762\u5c31\u5360\u636e\u4e86\u4e0a\u98ce\uff0c\u5e76\u4e14\u540e\u6765\u4e00\u76f4\u5728\u8fc5\u901f\u53d1\u5c55\u3002\u540c\u6837\u7684\u8bbe\u8ba1\u6a21\u5f0f\u5728C++\u4e2d\u4e0d\u4ec5\u4ec5\u53ef\u4ee5\u7528\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3\u5b9e\u73b0\uff0c\u4e5f\u53ef\u4ee5\u7528\u6cdb\u578b\u7f16\u7a0b\u7684\u601d\u60f3\u5b9e\u73b0\uff0c\u4e0d\u5c11\u65f6\u5019\u540e\u8005\u53ef\u80fd\u66f4\u795e\u5947\u66f4\u4f18\u96c5\u66f4\u9ad8\u6548\u3002<\/p>\n<p dir=\"auto\">\u9762\u5411\u5bf9\u8c61\u6ce8\u91cd\u7684\u662f\u4ee3\u7801\u7684\u6269\u5c55\u548c\u7ef4\u62a4\uff0c\u800c\u4e0d\u662f\u9ad8\u6027\u80fd\uff0c\u5728\u4e00\u4e9b\u9700\u8981\u9ad8\u6027\u80fd\u7684\u573a\u5408\uff0c\u50cf\u6211\u6240\u5728\u7684\u6e38\u620f\u9886\u57df\u9700\u8981\u4f18\u5316\u6027\u80fd\u7684\u5730\u65b9\uff0c\u4e0d\u80fd\u7528\u9762\u5411\u5bf9\u8c61\uff0c\u4ee5\u540e\u5982\u679c\u6211\u627e\u5230\u5408\u9002\u7684\u4f8b\u5b50\u4f5c\u4e3a\u7d20\u6750\uff0c\u6211\u4f1a\u518d\u5199\u4e00\u7bc7\u300c\u9762\u5411\u5bf9\u8c61\u7684\u7f3a\u70b9\u300d\u7684\u6587\u7ae0\u3002<\/p>\n<h3 dir=\"auto\"><a id=\"user-content-\u58f0\u660e\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%A3%B0%E6%98%8E\" aria-hidden=\"true\"><\/a>\u58f0\u660e<\/h3>\n<p dir=\"auto\">\u8bd1\u8005\u7eaf\u7cb9\u51fa\u4e8e\u5b66\u4e60\u76ee\u7684\u4e0e\u4e2a\u4eba\u5174\u8da3\u7ffb\u8bd1\u672c\u4e66\uff0c\u4e0d\u8ffd\u6c42\u4efb\u4f55\u7ecf\u6d4e\u5229\u76ca\u3002<\/p>\n<p dir=\"auto\">\u672c\u8bd1\u6587\u53ea\u4f9b\u5b66\u4e60\u7814\u7a76\u53c2\u8003\u4e4b\u7528\uff0c\u4e0d\u5f97\u516c\u5f00\u4f20\u64ad\u53d1\u884c\u6216\u7528\u4e8e\u5546\u4e1a\u7528\u9014\u3002\u6709\u80fd\u529b\u9605\u8bfb\u82f1\u6587\u4e66\u7c4d\u8005\u8bf7\u8d2d\u4e70\u6b63\u7248\u652f\u6301\u3002<\/p>\n<h3 dir=\"auto\"><a id=\"user-content-\u8bb8\u53ef\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E8%AE%B8%E5%8F%AF\" aria-hidden=\"true\"><\/a>\u8bb8\u53ef<\/h3>\n<p dir=\"auto\"><a href=\"https:\/\/github.com\/liuzengh\/design-pattern\/blob\/main\/LICENSE\">CC-BY 4.0<\/a><\/p>\n<h3 dir=\"auto\"><a id=\"user-content-\u53c2\u8003\" class=\"anchor\" href=\"https:\/\/github.com\/liuzengh\/design-pattern#%E5%8F%82%E8%80%83\" aria-hidden=\"true\"><\/a>\u53c2\u8003<\/h3>\n<ol dir=\"auto\">\n<li><a href=\"https:\/\/book.douban.com\/subject\/30200080\/\" rel=\"nofollow\">\u300aDesign Patterns In Modern C++\u300b<\/a><\/li>\n<li><a href=\"http:\/\/cppstdlib.com\/\" rel=\"nofollow\">\u300aThe C++ Standard Library &#8211; A Tutorial and Reference, 2nd Edition\u300b<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 &nbsp; \u52a8\u673a \u672c\u4e66\u7684\u793a\u4f8b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-5658","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5658"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5658\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}