<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Vasily Pereverzev</title>
    <description>The latest articles on Forem by Vasily Pereverzev (@vpereverzev).</description>
    <link>https://forem.com/vpereverzev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F291850%2Fee456bc9-e1c4-4099-b244-14dab457ff68.jpeg</url>
      <title>Forem: Vasily Pereverzev</title>
      <link>https://forem.com/vpereverzev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vpereverzev"/>
    <language>en</language>
    <item>
      <title>How to find a girl or dependency injection pattern in action. Part II</title>
      <dc:creator>Vasily Pereverzev</dc:creator>
      <pubDate>Tue, 07 Jan 2020 15:50:44 +0000</pubDate>
      <link>https://forem.com/vpereverzev/how-to-find-your-love-or-dependency-injection-pattern-in-action-part-ii-32po</link>
      <guid>https://forem.com/vpereverzev/how-to-find-your-love-or-dependency-injection-pattern-in-action-part-ii-32po</guid>
      <description>&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;In the previous &lt;a href="https://dev.to/vpereverzev/how-to-find-your-love-or-dependency-injection-pattern-in-action-part-i-3ba7"&gt;part&lt;/a&gt;, we introduced the basic concepts of the dependency injection pattern.&lt;/p&gt;

&lt;p&gt;Now it is time to make out an example implementation (in this example, I use the Qt / C ++ bundle). Let's imagine a basic simple case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5wxg4474g442ezai2uyx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5wxg4474g442ezai2uyx.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What can we see here?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Module A&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Interface &lt;strong&gt;IDummyInterface&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Service &lt;strong&gt;DummyService&lt;/strong&gt; that implements interface &lt;strong&gt;IDummyInterface&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Module B&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ServiceInjector&lt;/strong&gt; - the "dating agency".&lt;br&gt;
Picks up metadata (contacts) of the necessary service from ServiceResolver (agency database) and injects it in the client&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ServiceResolver&lt;/strong&gt; - the database of our "dating agency". Able to register services and submit their metadata (contacts) for subsequent injection&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Module C&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DummyClient&lt;/strong&gt; - client that needs the functionality declared in &lt;strong&gt;IDummyInterface&lt;/strong&gt;. At the same time, he doesn't want to know anything about the details of the implementation of &lt;strong&gt;DummyService&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;Add to the IDummyInterface interface the ability to represent ourselves through the unique identifier QUuid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;servicesresolver.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IDummyInterface&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;INTERFACE_ID&lt;/span&gt;

    &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The implementation of the macro is extremely simple - just creating a unique identifier.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#define INTERFACE_ID                             \
    public:                                      \
    static const QUuid interfaceId() {           \
        static QUuid id = QUuid::createUuid();   \
        return id;                               \
    }                                            \
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;Register the DummyService, the implementation of the IDummyInterface.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;ServicesResolver&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;registerService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDummyInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DummyService&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="p"&gt;[]()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;DummyService&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DummyService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;OR&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in case of singleton&lt;/span&gt;

&lt;span class="n"&gt;ServicesResolver&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;registerService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDummyInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DummyService&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;DummyService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;Inherit our client from &lt;strong&gt;ServiceInjector&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"serviceinjector.h"&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"interfaces/idummyinterface.h"&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DummyClient&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ServiceInjector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDummyInterface&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Inject dependency to the client:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"serviceinjector.h"&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"interfaces/idummyinterface.h"&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DummyClient&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;ServiceInjector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IDummyInterface&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;INJECT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IDummyInterface&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dummyService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="p"&gt;.....&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The INJECT macro implementation is a simple setter and getter.&lt;br&gt;
The first parameter is the type of interface.&lt;br&gt;
The second parameter - an alias for the service in the scope of the client, needed for simplify calls of a service.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#define INJECT(INTERFACE_NAME, ALIAS)                              \
public:                                                            \
    INTERFACE_NAME* ALIAS() {                                      \
        return ServiceInjector&amp;lt;INTERFACE_NAME&amp;gt;::getService();      \
    }                                                              \
                                                                   \
    void set##ALIAS(INTERFACE_NAME* impl) {                        \  
&lt;/span&gt;        &lt;span class="n"&gt;ServiceInjector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;INTERFACE_NAME&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;::&lt;/span&gt;&lt;span class="n"&gt;setService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;impl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         \
    &lt;span class="p"&gt;}&lt;/span&gt;                                                              \
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The full implementation details and code-snippets can be found at our open-source project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/musescore" rel="noopener noreferrer"&gt;
        musescore
      &lt;/a&gt; / &lt;a href="https://github.com/musescore/MuseScore" rel="noopener noreferrer"&gt;
        MuseScore
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a rel="noopener noreferrer" href="https://github.com/musescore/MuseScoreshare/icons/musescore_logo_full.png"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fmusescore%2FMuseScoreshare%2Ficons%2Fmusescore_logo_full.png" alt="MuseScore"&gt;&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;Music notation and composition software&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gnu.org/licenses/gpl-3.0.en.html" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/93ca07ea63e4649ae72b87de86d82eedeab50e744fa6e07ee95e5344779fb930/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076332d626c75652e737667" alt="License: GPL v3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MuseScore is an open source and free music notation software. For support, contribution, and bug reports visit MuseScore.org. Fork and make pull requests!&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;WYSIWYG design, notes are entered on a "virtual notepaper"&lt;/li&gt;
&lt;li&gt;TrueType font(s) for printing &amp;amp; display allows for high quality scaling to all sizes&lt;/li&gt;
&lt;li&gt;Easy &amp;amp; fast note entry&lt;/li&gt;
&lt;li&gt;Many editing functions&lt;/li&gt;
&lt;li&gt;MusicXML import/export&lt;/li&gt;
&lt;li&gt;MIDI (SMF) import/export&lt;/li&gt;
&lt;li&gt;MEI import/export&lt;/li&gt;
&lt;li&gt;MuseData import&lt;/li&gt;
&lt;li&gt;MIDI input for note entry&lt;/li&gt;
&lt;li&gt;Integrated sequencer and software synthesizer to play the score&lt;/li&gt;
&lt;li&gt;Print or create PDF files&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;More info&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://musescore.org" rel="nofollow noopener noreferrer"&gt;MuseScore Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://musescore.org/en/developers-handbook/git-workflow" rel="nofollow noopener noreferrer"&gt;MuseScore Git workflow instructions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/musescore/MuseScore/wiki/Set-up-developer-environment" rel="noopener noreferrer"&gt;How to compile MuseScore?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;License&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;MuseScore is licensed under GPL version 3.0. See &lt;a href="https://github.com/musescore/MuseScore/blob/master/LICENSE.txt" rel="noopener noreferrer"&gt;license file&lt;/a&gt; in the same directory.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Packages&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;See &lt;a href="https://github.com/musescore/MuseScore/wiki/CodeStructure" rel="noopener noreferrer"&gt;Code Structure on Wiki&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Building&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Read the &lt;a href="https://github.com/musescore/MuseScore/wiki/Set-up-developer-environment" rel="noopener noreferrer"&gt;Compilation section&lt;/a&gt; of the &lt;a href="https://github.com/musescore/MuseScore/wiki" rel="noopener noreferrer"&gt;MuseScore Wiki&lt;/a&gt; for a complete build walkthrough and a list of dependencies.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Getting sources&lt;/h3&gt;

&lt;/div&gt;

&lt;p&gt;If using git to download repo of entire…&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/musescore/MuseScore" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>How to find a girl or dependency injection pattern in action. Part I</title>
      <dc:creator>Vasily Pereverzev</dc:creator>
      <pubDate>Tue, 07 Jan 2020 15:50:39 +0000</pubDate>
      <link>https://forem.com/vpereverzev/how-to-find-your-love-or-dependency-injection-pattern-in-action-part-i-3ba7</link>
      <guid>https://forem.com/vpereverzev/how-to-find-your-love-or-dependency-injection-pattern-in-action-part-i-3ba7</guid>
      <description>&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;Many large projects as they grow inevitably face the following list of problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Сomplexity
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gubXAD8t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/g4tjzqx3sn1qd5h6s0z8.jpg" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Concentration of motley logic in one place, blurred responsibility, classes of several thousand lines. Familiar symptoms right?&lt;/p&gt;

&lt;p&gt;To combat the high complexity of logic, there is a good old divide-and-conquer technique. As a rule, complex things consist of a subset of simple ones that is is much easier to understand.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Coupling
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9u-Ub6Gj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e3kr7dxc72vv2sc3cywn.jpg" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Changed or added logic in one part of the application, but broke in completely different one (maybe even completely unrelated at first glance).&lt;br&gt;
Classes interact very closely with each other and each of them strictly relies on the implementation of its neighbors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lovely dependency injection
&lt;/h3&gt;

&lt;p&gt;There are many technical articles on this subject, but let's have some fun and try to dilute the explanation with exaggerated analogies.&lt;/p&gt;

&lt;p&gt;Meet, ladies and gentlemen, the very abstract Peter:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--23VY3VCC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mvhlkwwkd0n77kzm3aky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--23VY3VCC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mvhlkwwkd0n77kzm3aky.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see from the illustration, Peter is a pianist with a great sense of humor. Pretty good guy, huh? &lt;/p&gt;

&lt;p&gt;However, Peter does not have enough female attention for complete happiness. So he decides to find a girl.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5XTSEUH7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nplyy90qn7iycevp7b03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5XTSEUH7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/nplyy90qn7iycevp7b03.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Peter wanders around clubs and pubs, attends theme parties, tries to seduce female colleagues. But all to no avail... The perfect, the NECESSARY girl has not yet been found...&lt;/p&gt;

&lt;p&gt;Finally, tired and sad Peter decides to abandon these attempts and focus on his work.&lt;/p&gt;

&lt;p&gt;But the dream of great love nevertheless glimmers in him and he decides to APPEAL to a specialized dating service to shift burden of searching the second half for SPECIALLY TRAINED people.&lt;/p&gt;

&lt;p&gt;When addressing, Peter fills out a form in which he describes in detail the girl of his dreams.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--egsTjhme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h8pywysro79h7tb3503o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--egsTjhme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/h8pywysro79h7tb3503o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It turns out that Peter is not only a wonderful musician, but also a lucky one.&lt;br&gt;
Because the perfect candidate was quickly found in the agency database. In accordance with all the wishes of Peter.&lt;/p&gt;

&lt;p&gt;The agency sends the girl’s contacts to our musician. Well, then magic of love, romance and "they lived happily ever after."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-QeaVdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/y1bkk830o4wapepc1952.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z-QeaVdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/y1bkk830o4wapepc1952.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Take off the mask
&lt;/h3&gt;

&lt;p&gt;Well, now it's time to take off the masks and move on to the realities of development in terms of Dependency Injection:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client&lt;/strong&gt; - our Peter, a consumer who needed some value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interface&lt;/strong&gt; - the form that Peter filled out&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Injector&lt;/strong&gt; - a dating agency that picked up a girl for Peter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Service&lt;/strong&gt; - the beloved of Peter, whom he has sought for so long&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IoC(inversion of control) container&lt;/strong&gt; - the agency's database&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please note that in the first case, Peter acted ACTIVELY and independently tried to find his &lt;strong&gt;Service&lt;/strong&gt;, but at the same time he completely forgot about his main activity.&lt;/p&gt;

&lt;p&gt;He later delegated responsibility to the agency and spoke in a PASSIVE position.&lt;br&gt;
All he did was declare his needs(INTERFACE) and leave contact details for communication.&lt;br&gt;
So the special service(AGENCY) easily fulfilled its only responsibility - to find a couple for Peter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusions
&lt;/h3&gt;

&lt;p&gt;This pattern allows to separate and isolate clients from dependency implementation. All it needs is an interface. Clients can be concentrated on their own activities, because all dirty work would be done automatically by special INJECTOR service beyond the scope of a CLIENT.&lt;/p&gt;

&lt;p&gt;Additionally, an isolated class is very easy to test with unit tests, because under the mask of the interface you can enclose MOCK or FAKE.&lt;/p&gt;




</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
