{"id":6454,"date":"2022-10-02T15:08:59","date_gmt":"2022-10-02T15:08:59","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/the-singleton-the-alternatives\/"},"modified":"2023-06-26T08:58:21","modified_gmt":"2023-06-26T08:58:21","slug":"the-singleton-the-alternatives","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/the-singleton-the-alternatives\/","title":{"rendered":"The Singleton: The Alternatives Monostate Pattern and Dependency Injection"},"content":{"rendered":"<p>So far, I have discussed in my previous posts the Singleton Pattern, and its pros and cons. One question is still open: What alternatives for the Singleton Pattern are available? Today, I write about the Monostate Pattern and Dependency Injection.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6435\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/09\/CreationalPatterns.png\" alt=\"CreationalPatterns\" width=\"650\" height=\"330\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/09\/CreationalPatterns.png 1220w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/09\/CreationalPatterns-300x152.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/09\/CreationalPatterns-1024x520.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/09\/CreationalPatterns-768x390.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>I want to start this post with the Monostate Pattern.<\/p>\n<h2>The Monostate Pattern<\/h2>\n<p>The <a href=\"https:\/\/wiki.c2.com\/?MonostatePattern\">Monostate Pattern<\/a> is similar to the Singleton Pattern and quite popular in Python. While the Singleton Pattern guarantees that only one instance of a class exists, the Monostate Pattern ensures that all instances of a class share the same state. The Monostate Pattern is also known as Borgidiom, because the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Borg\">Borgs<\/a> in the Star Trek series share a common memory.<\/p>\n<p>In the Monostate Pattern, all data members are <code>static<\/code>. Consequentially, all instances of the class use the same data. The member function to access the data are non-<code>static<\/code>. Users of the instances are unaware of the singleton-like behavior of the class.<\/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;\">\/\/ monostate.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;unordered_map&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Monostate<\/span> {\r\n  \r\n <span style=\"color: #9999ff;\">public:<\/span>\r\n    \r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> addNumber(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string<span style=\"color: #555555;\">&amp;<\/span> na, <span style=\"color: #007788; font-weight: bold;\">int<\/span> numb) {\r\n        teleBook[na] <span style=\"color: #555555;\">=<\/span> numb;\r\n    }\r\n \r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> getEntries () <span style=\"color: #006699; font-weight: bold;\">const<\/span> {\r\n        <span style=\"color: #006699; font-weight: bold;\">for<\/span> (<span style=\"color: #006699; font-weight: bold;\">auto<\/span> ent<span style=\"color: #555555;\">:<\/span> teleBook){ \r\n            std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> ent.first <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\": \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> ent.second <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n        }\r\n    }\r\n    \r\n<span style=\"color: #9999ff;\">private:<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">static<\/span> std<span style=\"color: #555555;\">::<\/span>unordered_map<span style=\"color: #555555;\">&lt;<\/span>std<span style=\"color: #555555;\">::<\/span>string, <span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> teleBook;\r\n \r\n};\r\n\r\nstd<span style=\"color: #555555;\">::<\/span>unordered_map<span style=\"color: #555555;\">&lt;<\/span>std<span style=\"color: #555555;\">::<\/span>string, <span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> Monostate<span style=\"color: #555555;\">::<\/span>teleBook{};\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    Monostate tele1;\r\n    Monostate tele2;\r\n    tele1.addNumber(<span style=\"color: #cc3300;\">\"grimm\"<\/span>, <span style=\"color: #ff6600;\">123<\/span>);\r\n    tele2.addNumber(<span style=\"color: #cc3300;\">\"huber\"<\/span>, <span style=\"color: #ff6600;\">456<\/span>);\r\n    tele1.addNumber(<span style=\"color: #cc3300;\">\"smith\"<\/span>, <span style=\"color: #ff6600;\">789<\/span>);\r\n    \r\n    tele1.getEntries();\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    tele2.getEntries();\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>Each instance of the class <code>Monostate<\/code> shares the same state:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6452\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/monostate.jpg\" alt=\"monostate\" width=\"350\" height=\"273\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/monostate.jpg 757w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/monostate-300x234.jpg 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>You probably think about Dependency Injection in the first place when you search for the alternative for the Singleton Pattern.<\/p>\n<\/p>\n<h2>Dependency Injection<\/h2>\n<p>The Singleton Pattern has serious drawbacks that I described in the previous post &#8220;The Singleton: Pros and Cons&#8221;, Consequentially, the Singleton Pattern would probably not be part of a reprint of the book &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Design_Patterns\">Design Patterns: Elements of Reusable Object-Oriented Software&#8221;<\/a>. Instead, Dependency Injection is a highly likely future candidate.<\/p>\n<p>The key idea of Dependency Injection is that an object or function (client) receives the other service it depends on. Therefore, the client is not aware of the construction of the service. The client is fully separated from the service that is injected by an injector. This is in contrast to the Singleton Pattern, where the client creates the service if needed.<\/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: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">client<\/span>(){\r\n  \r\n  ...\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">auto<\/span> singleton <span style=\"color: #555555;\">=<\/span> Singleton<span style=\"color: #555555;\">::<\/span>getInstance();\r\n  singleton.doSomething();\r\n\r\n  ...\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Dependency Injection is a form of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Inversion_of_control\">inversion of control.<\/a> Not the client creates and calls the service, but the injector injects the service into the client.<\/p>\n<p>In C++, three types of Dependency Injection are typically used:<\/p>\n<ul>\n<li>Constructor injection<\/li>\n<li>Setter injection<\/li>\n<li>Template parameter injection<\/li>\n<\/ul>\n<p>I use constructor injection and setter injection in the following program <code>dependencyInjection.cpp<\/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;\">\/\/ dependencyInjection.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;chrono&gt;<\/span>\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;\">Logger<\/span> {\r\n<span style=\"color: #9999ff;\">public:<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">virtual<\/span> <span style=\"color: #007788; font-weight: bold;\">void<\/span> write(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string<span style=\"color: #555555;\">&amp;<\/span>) <span style=\"color: #006699; font-weight: bold;\">const<\/span> <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">0<\/span>;\r\n    <span style=\"color: #006699; font-weight: bold;\">virtual<\/span> <span style=\"color: #555555;\">~<\/span>Logger() <span style=\"color: #555555;\">=<\/span> <span style=\"color: #006699; font-weight: bold;\">default<\/span>;\r\n};\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">SimpleLogger<\/span><span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> Logger {\r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> write(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string<span style=\"color: #555555;\">&amp;<\/span> mess) <span style=\"color: #006699; font-weight: bold;\">const<\/span> override {\r\n        std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> mess <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n    }\r\n};\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">TimeLogger<\/span><span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> Logger {\r\n    <span style=\"color: #006699; font-weight: bold;\">typedef<\/span> std<span style=\"color: #555555;\">::<\/span>chrono<span style=\"color: #555555;\">::<\/span>duration<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">long<\/span> <span style=\"color: #007788; font-weight: bold;\">double<\/span><span style=\"color: #555555;\">&gt;<\/span> MySecondTick;\r\n    <span style=\"color: #007788; font-weight: bold;\">long<\/span> <span style=\"color: #007788; font-weight: bold;\">double<\/span> <span style=\"color: #cc00ff;\">timeSinceEpoch<\/span>() <span style=\"color: #006699; font-weight: bold;\">const<\/span> {\r\n        <span style=\"color: #006699; font-weight: bold;\">auto<\/span> timeNow <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span>chrono<span style=\"color: #555555;\">::<\/span>system_clock<span style=\"color: #555555;\">::<\/span>now();\r\n        <span style=\"color: #006699; font-weight: bold;\">auto<\/span> duration <span style=\"color: #555555;\">=<\/span> timeNow.time_since_epoch();\r\n        MySecondTick <span style=\"color: #cc00ff;\">sec<\/span>(duration);\r\n        <span style=\"color: #006699; font-weight: bold;\">return<\/span> sec.count();\r\n    }\r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> write(<span style=\"color: #006699; font-weight: bold;\">const<\/span> std<span style=\"color: #555555;\">::<\/span>string<span style=\"color: #555555;\">&amp;<\/span> mess) <span style=\"color: #006699; font-weight: bold;\">const<\/span> override {\r\n        std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>fixed;\r\n        std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Time since epoch: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> timeSinceEpoch() <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\": \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> mess <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n    }\r\n\r\n};\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">Client<\/span> {\r\n<span style=\"color: #9999ff;\">public:<\/span>\r\n    Client(std<span style=\"color: #555555;\">::<\/span>shared_ptr<span style=\"color: #555555;\">&lt;<\/span>Logger<span style=\"color: #555555;\">&gt;<\/span> log)<span style=\"color: #555555;\">:<\/span> logger(log) {}   <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> doSomething() {\r\n        logger<span style=\"color: #555555;\">-&gt;<\/span>write(<span style=\"color: #cc3300;\">\"Message\"<\/span>);\r\n    }\r\n    <span style=\"color: #007788; font-weight: bold;\">void<\/span> setLogger(std<span style=\"color: #555555;\">::<\/span>shared_ptr<span style=\"color: #555555;\">&lt;<\/span>Logger<span style=\"color: #555555;\">&gt;<\/span> log) {         <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\r\n        logger <span style=\"color: #555555;\">=<\/span> log;\r\n    }\r\n<span style=\"color: #9999ff;\">private:<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>shared_ptr<span style=\"color: #555555;\">&lt;<\/span>Logger<span style=\"color: #555555;\">&gt;<\/span> logger;\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    Client cl(std<span style=\"color: #555555;\">::<\/span>make_shared<span style=\"color: #555555;\">&lt;<\/span>SimpleLogger<span style=\"color: #555555;\">&gt;<\/span>());\r\n    cl.doSomething();\r\n    cl.setLogger(std<span style=\"color: #555555;\">::<\/span>make_shared<span style=\"color: #555555;\">&lt;<\/span>TimeLogger<span style=\"color: #555555;\">&gt;<\/span>());\r\n    cl.doSomething();\r\n    cl.doSomething();\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>The client<code> cl<\/code> requires logger functionality. First, the logger <code>SimpleLogger<\/code> is injected using the constructor (line 1), afterwards the logger is replaced with the more powerful logger <code>TimeLogger<\/code>. The setter member function allows it to inject the new logger. The client is fully decoupled from the logger. It simply supports the interfaces to inject loggers.&nbsp;<\/p>\n<p>Here is the output of the program.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6453\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/dependencyInjection.jpg\" alt=\"dependencyInjection\" width=\"500\" height=\"195\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/dependencyInjection.jpg 1085w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/dependencyInjection-300x117.jpg 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/dependencyInjection-1024x400.jpg 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2022\/10\/dependencyInjection-768x300.jpg 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>There are many examples of Dependency Injection using template parameters in the Standard Template Library. I only name here a few of the containers.<\/p>\n<ul>\n<li>The containers of the STL use a default allocator. This one can be replaced with a custom allocator.<\/li>\n<li>The ordered associative container use <code>std::less<\/code> as the sorting criteria. Of course, you can replace it with another sorting criterion.<\/li>\n<li>The unordered associative containers require a hash function and an equal function. Both are template parameters and can, therefore, be replaced.<\/li>\n<\/ul>\n<p>Finally, let me write a few words about the three remaining creational Design Patterns.<\/p>\n<h2>The Three Remaining Creational Design Patterns<\/h2>\n<h3>Abstract Factory<\/h3>\n<p>Abstract Factory lets you produce families of related objects without specifying their concrete classes. A typical example could be an IDE theme that consists of many related objects. For example, each IDE theme has different widgets, such as checkboxes, sliders, push buttons, and radio buttons. Typically, a concrete IDE theme has different factory methods for the various checkboxes, sliders, push buttons, and radio buttons .. .&nbsp; A client could change the IDE theme and, therefore, the widgets during the use of the IDE.<\/p>\n<h3>Builder<\/h3>\n<p>Builder construct complex objects step by step. Thanks to the builder pattern, you can produce different types and representations of an object using the same stepwise construction process. The builder extracts the object construction code out of its class and moves it to separate objects called builders. Not all steps of the construction process must be called, and a step can have more than one builder.<\/p>\n<h3>Prototype<\/h3>\n<p>Prototype creates objects by cloning an existing object. The program <code>factoryMethodWindowSlicingFixed.cpp <\/code>in my previous post &#8220;<a href=\"https:\/\/www.modernescpp.com\/index.php\/factory-method-2\">The Factory Method (Slicing and Ownership Semantics)<\/a>&#8221; is a prototype. The Prototype Pattern is similar to the <a href=\"https:\/\/www.modernescpp.com\/index.php\/factory-method\">factory method<\/a>, but emphasizes the created prototypes&#8217; initialization. The factory method creates different objects by subclassing them.&nbsp;<\/p>\n<h2>What&#8217;s Next?<\/h2>\n<p>My next posts about Design Patterns are dedicated to the structural pattern. I will start with the adaptor pattern, which can be implemented in two ways: multiple inheritance or delegation.<\/p>\n<p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So far, I have discussed in my previous posts the Singleton Pattern, and its pros and cons. One question is still open: What alternatives for the Singleton Pattern are available? Today, I write about the Monostate Pattern and Dependency Injection.<\/p>\n","protected":false},"author":21,"featured_media":6435,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[379],"tags":[406,405,404],"class_list":["post-6454","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-patterns","tag-dependency-injection","tag-monostate","tag-singleton"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6454","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=6454"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6454\/revisions"}],"predecessor-version":[{"id":6657,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6454\/revisions\/6657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/6435"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=6454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=6454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=6454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}