{"id":6478,"date":"2022-11-13T08:35:38","date_gmt":"2022-11-13T08:35:38","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/the-proxy-pattern\/"},"modified":"2023-08-20T14:41:38","modified_gmt":"2023-08-20T14:41:38","slug":"the-proxy-pattern","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/the-proxy-pattern\/","title":{"rendered":"The Proxy Pattern"},"content":{"rendered":"<p>The Proxy Pattern is probably the most influential design pattern for C++. The Proxy provides a placeholder for accessing another object.<\/p>\n<p><!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6385\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/06\/patterns.png\" alt=\"patterns\" width=\"650\" height=\"330\" style=\"display: block; margin-left: auto; margin-right: auto;\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The proxy pattern is one of the seven structural patterns from the book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Design_Patterns\">Design Patterns: Elements of Reusable Object-Oriented Software&#8221;<\/a>. A proxy controls access to another object, allowing you to perform additional operations before or after you access the original object. Sound familiar?<\/p>\n<p>Which idiom is characteristic of C++? Right: RAII (<strong>R<\/strong>esource <strong>A<\/strong>cquisition <strong>I<\/strong>s<strong> I<\/strong>nitialization). RAII is the C++ way to implement the Proxy Pattern. Here are the facts about the Proxy Pattern.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Proxy_Pattern\"><\/span>Proxy Pattern<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Purpose\"><\/span>Purpose<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Provides a placeholder for accessing another object.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Also_Known_As\"><\/span>Also Known As<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Surrogate<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Use_Case\"><\/span>Use Case<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Control access to another object\n<ul>\n<li>Remote proxy (acts as an intermediary for a remote service)<\/li>\n<li>Virtual proxy (creates an object lazily on request)<\/li>\n<li>Security proxy (adds security to a request)<\/li>\n<li>Caching proxy (delivers cached requests)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Structure\"><\/span>Structure<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6476\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/Proxy.png\" alt=\"Proxy\" width=\"421\" height=\"215\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/Proxy.png 421w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/Proxy-300x153.png 300w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"i\"><\/span>&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code><strong>Proxy<\/strong><\/code><\/p>\n<ul>\n<li>Controls the access and lifetime of the <code>RealSubject<\/code><\/li>\n<li>Supports the same interface as <code>RealSubject<\/code><\/li>\n<\/ul>\n<p><strong><code>Subject<\/code><\/strong><\/p>\n<ul>\n<li>Defines the interface of the <code>Proxy<\/code> and the <code>RealSubject<\/code><\/li>\n<\/ul>\n<p><strong><code>RealSubject<\/code><\/strong><\/p>\n<ul>\n<li>Implements the interface<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The following examples use two generic proxies: <code>std::unique_ptr<\/code> and <code>std::shared_ptr<\/code>.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ proxy.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;memory&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">MyInt<\/span>{\r\n <span style=\"color: #9999ff;\">public:<\/span>\r\n    MyInt(<span style=\"color: #007788; font-weight: bold;\">int<\/span> i)<span style=\"color: #555555;\">:<\/span>i_(i){}\r\n    <span style=\"color: #007788; font-weight: bold;\">int<\/span> getValue() <span style=\"color: #006699; font-weight: bold;\">const<\/span> {\r\n        <span style=\"color: #006699; font-weight: bold;\">return<\/span> i_;\r\n    }\r\n <span style=\"color: #9999ff;\">private:<\/span>\r\n    <span style=\"color: #007788; font-weight: bold;\">int<\/span> i_;\r\n};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n    MyInt<span style=\"color: #555555;\">*<\/span> myInt <span style=\"color: #555555;\">=<\/span> <span style=\"color: #006699; font-weight: bold;\">new<\/span> MyInt(<span style=\"color: #ff6600;\">1998<\/span>);                     <span style=\"color: #0099ff; font-style: italic;\">\/\/ (3)<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"myInt-&gt;getValue(): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> myInt<span style=\"color: #555555;\">-&gt;<\/span>getValue() <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>unique_ptr<span style=\"color: #555555;\">&lt;<\/span>MyInt<span style=\"color: #555555;\">&gt;<\/span> uniquePtr{<span style=\"color: #006699; font-weight: bold;\">new<\/span> MyInt(<span style=\"color: #ff6600;\">1998<\/span>)};  <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"uniquePtr-&gt;getValue(): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> uniquePtr<span style=\"color: #555555;\">-&gt;<\/span>getValue() <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>shared_ptr<span style=\"color: #555555;\">&lt;<\/span>MyInt<span style=\"color: #555555;\">&gt;<\/span> sharedPtr{<span style=\"color: #006699; font-weight: bold;\">new<\/span> MyInt(<span style=\"color: #ff6600;\">1998<\/span>)};  <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"sharedPtr-&gt;getValue(): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> sharedPtr<span style=\"color: #555555;\">-&gt;<\/span>getValue() <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Both smart pointers can transparently access the member function<code> getValue<\/code> of <code>MyInt<\/code>. It makes no difference if you call the member function <code>getValue<\/code> on the <code>std::unique_ptr<\/code>, (line 1) on the<code> std::shared_ptr<\/code>, (line 2), or on the object directly. All calls return the same value:<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6477\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/proxy_.png\" alt=\"proxy\" width=\"407\" height=\"244\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/proxy_.png 407w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/11\/proxy_-300x180.png 300w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Known_Uses\"><\/span>Known Uses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The smart pointers model the Proxy Pattern in C++. Additionally, the RAII Idiom is the C++ adaption of the Proxy Pattern. RAII is the crucial idiom in C++. I will write more about it in a few lines.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Related_Patterns\"><\/span>Related Patterns<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>The<a href=\"https:\/\/en.wikipedia.org\/wiki\/Adapter_pattern\"> Adaptor Pattern<\/a> adjusts an existing interface, but the Facade creates a new simplified interface.<\/li>\n<li>The<a href=\"https:\/\/en.wikipedia.org\/wiki\/Decorator_pattern\"> Decorator Pattern<\/a> is structurally similar to the Proxy, but the Decorator has a different purpose. A Decorator extends an object with additional responsibilities. A Proxy controls access to an object.<\/li>\n<li>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Facade_pattern\">Facade Pattern<\/a> is similar to the Proxy because it encapsulates access to an object. The Facade does not support the same interface as the Proxy but supports a simplified one.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Pros_and_Cons\"><\/span>Pros and Cons<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4>Pros<\/h4>\n<ul>\n<li>The underlying object is fully transparent to the client.<\/li>\n<li>The proxy can answer requests directly without using the client<\/li>\n<li>The proxy can be transparently extended or replaced with another proxy.<\/li>\n<\/ul>\n<h4>Cons<\/h4>\n<ul>\n<li>The separation of the proxy and the object makes the code more difficult<\/li>\n<li>The forwarded proxy calls may be performance critical<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"RAII_Idiom\"><\/span>RAII Idiom<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>RAII stands for <strong>R<\/strong>esource <strong>A<\/strong>cquisition <strong>I<\/strong>s <strong>I<\/strong>nitialization. The most crucial idiom in C++ is that a resource should be acquired in the constructor and released in the object&#8217;s destructor. The key idea is that the destructor will automatically be called if the object goes out of scope. Or, to put it differently: <strong>A resource&#8217;s lifetime is bound to a local variable&#8217;s lifetime, and C++ automatically manages the lifetime of locals.<\/strong><\/p>\n<p>There is one big difference between the Proxy Pattern and the RAII Idiom in C++. In the classical Proxy Pattern, the Proxy and the RealObject (object) implement the same interface. Therefore, you invoke a member function on the proxy, and this call is delegated to the object. On the contrary, it is typical for RAII to do the operation on the object implicitly.<\/p>\n<p>The following example shows the deterministic behavior of RAII in C++.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0px; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ raii.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;new&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">ResourceGuard<\/span>{\r\n  <span style=\"color: #9999ff;\">private:<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string resource;\r\n  <span style=\"color: #9999ff;\">public:<\/span>\r\n    ResourceGuard(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string<span style=\"color: #555555;\">&amp;<\/span> res)<span style=\"color: #555555;\">:<\/span>resource(res){\r\n      std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Acquire the \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> resource <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\".\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span>  <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n    }\r\n    <span style=\"color: #555555;\">~<\/span>ResourceGuard(){\r\n      std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Release the \"<\/span><span style=\"color: #555555;\">&lt;&lt;<\/span> resource <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\".\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n    }\r\n};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>() {\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n  ResourceGuard resGuard1{<span style=\"color: #cc3300;\">\"memoryBlock1\"<\/span>};             <em><span style=\"color: #0099ff;\"> \/\/ (1)<\/span><\/em>\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">Before local scope\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  {\r\n    ResourceGuard resGuard2{<span style=\"color: #cc3300;\">\"memoryBlock2\"<\/span>};            <em><span style=\"color: #0099ff;\">\/\/ (3)<\/span><\/em>\r\n  }                                                     <em><span style=\"color: #0099ff;\">\/\/ (4)<\/span><\/em>\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"After local scope\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">Before try-catch block\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  try{\r\n      ResourceGuard resGuard3{<span style=\"color: #cc3300;\">\"memoryBlock3\"<\/span>};\r\n      <span style=\"color: #006699; font-weight: bold;\">throw<\/span> std<span style=\"color: #555555;\">::<\/span>bad_alloc();                          <em><span style=\"color: #0099ff;\">\/\/ (5)<\/span><\/em>\r\n  }   \r\n  <span style=\"color: #006699; font-weight: bold;\">catch<\/span> (std<span style=\"color: #555555;\">::<\/span>bad_alloc<span style=\"color: #555555;\">&amp;<\/span> e){                           <em><span style=\"color: #0099ff;\">\/\/ (6)<\/span><\/em>\r\n      std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> e.what();\r\n  }\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">After try-catch block\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n}                                                     <em><span style=\"color: #0099ff;\">\/\/ (2)\r\n<\/span><\/em><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: courier new, courier;\">ResourceGuard<\/span> is a guard that manages its resource. In this case, the string stands for the resource. <span style=\"font-family: courier new, courier;\">ResourceGuard<\/span> creates in its constructor the resource and releases the resource in its destructor. It does its job very decent.<\/p>\n<p>The destructor of <span style=\"font-family: courier new, courier;\">resGuard1<\/span> (line 1) is called at the end of the <span style=\"font-family: courier new, courier;\">main<\/span> function (line 2). The lifetime of <span style=\"font-family: courier new, courier;\">resGuard2<\/span> (line 3) already ends in line 4. Therefore, the destructor is automatically executed. Even the throwing of an exception does not affect the reliability of <span style=\"font-family: courier new, courier;\">resGuard3<\/span> (line 5). The destructor is called at the end of the <span style=\"font-family: courier new, courier;\">try<\/span> block (line 6).<\/p>\n<p>The screenshot shows the lifetimes of the objects.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5101\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/12\/raii.png\" alt=\"raii\" width=\"456\" height=\"372\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/12\/raii.png 456w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/12\/raii-300x245.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/p>\n<p>It&#8217;s pretty easy to apply the RAII Idiom to make out the <code>ResourceGuard<\/code> a <code>LockGuard<\/code>:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">LockGuard<\/span>{\r\n  <span style=\"color: #9999ff;\">private:<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">static inline<\/span> std<span style=\"color: #555555;\">::<\/span>mutex m;\r\n  <span style=\"color: #9999ff;\">public:<\/span>\r\n    LockGuard() {\r\n        m.lock();\r\n    }\r\n    <span style=\"color: #555555;\">~<\/span>LockGuard() {\r\n        m.unlock();\r\n    }\r\n};\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>All instances of <code>LockGuard<\/code> share the same mutex <code>m<\/code>. When an instance goes out of scope, it automatically unlocks its mutex <code>m<\/code>.<\/p>\n<p>I wrote that the RAII Idiom is the most crucial idiom in C++. Let me name a few prominent examples.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Applications_of_RAII\"><\/span>Applications of RAII<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><strong>Containers of the STL, including<code> std::string<\/code><\/strong>: they automatically allocate in the constructor and deallocate in their destructor<\/li>\n<li><strong>Smart Pointers<\/strong>: <code>std::unqiue_ptr<\/code> and<code> std::shared_ptr<\/code> take ownership of the underlying raw pointer; they delete the underlying raw pointer if it is not needed anymore.<\/li>\n<li><strong>Locks<\/strong>: <code>std::lock_guard<\/code>, <code>std::unique_lock<\/code>, <code>std::shared_lock<\/code>, and <code>std::scoped_lock <\/code>lock in their constructor the underlying mutex and unlock it in their destructor automatically<\/li>\n<li><code><strong>std::jthread<\/strong><\/code>: <code>std::jthread<\/code> in C++20 is an improved <code>std::thread<\/code> from C++11;<code> std::jthread<\/code> automatically joins in its destructor if necessary<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Whats_Next\"><\/span>What&#8217;s Next?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In my next post, I will continue my journey through the patterns of the book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Design_Patterns\">Design Patterns: Elements of Reusable Object-Oriented Software&#8221;<\/a>. The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Observer_pattern\">Observer Pattern<\/a> is a behavioral pattern that should be in the toolbox of each professional programmer.<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Proxy Pattern is probably the most influential design pattern for C++. The Proxy provides a placeholder for accessing another object.<\/p>\n","protected":false},"author":21,"featured_media":6385,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[379],"tags":[402,400,399,401],"class_list":["post-6478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-patterns","tag-policy","tag-shared_ptr","tag-smart-pointers","tag-unique_ptr"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=6478"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6478\/revisions"}],"predecessor-version":[{"id":6655,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6478\/revisions\/6655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/6385"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=6478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=6478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=6478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}