{"id":2120,"date":"2020-10-21T10:51:06","date_gmt":"2020-10-21T08:51:06","guid":{"rendered":"http:\/\/web.evertop.pl\/understanding-solid-principles-dependency-inversion\/"},"modified":"2020-10-23T20:57:04","modified_gmt":"2020-10-23T18:57:04","slug":"understanding-solid-principles-dependency-inversion","status":"publish","type":"post","link":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/","title":{"rendered":"Understanding SOLID Principles: Dependency Inversion"},"content":{"rendered":"<p>This is the last article related to the set of SOLID project principles. The DIP principle is the most useful of all in terms of its relevance to the creation of strong classes and good architecture of the whole system.<\/p>\n<h2>What can go wrong?<\/h2>\n<p>When we create the classes or other code structures, they will always depend on other elements, such as:<\/p>\n<ul>\n<li>The libraries included in the framework.<\/li>\n<li>The libraries from other suppliers.<\/li>\n<li>Other elements of the system<\/li>\n<\/ul>\n<p>It is not too hard to guess that the above classification comes from the extent of the variability of the elements, which our class depends on. We can easily state that the elements of the framework will be the least variable. The perfect example is the string class. Its implementation is practically invariable. On the other hand, there are obviously further elements of the system that are being created in the meantime \u2013 they can be modified during the whole software programming cycle. The libraries of the other suppliers should also be treated as variables. For this simple reason that there might be a need for them to be changed. Relating the class for instance, to the variable elements, brings the risk of modification in other dependent elements.<\/p>\n<h2>The Adjustments<\/h2>\n<p>We can\u2019t avoid the situation where our classes are independent from other partial elements of the system. By introducing a small change into our code we can achieve much better stability of our system. Our classes should depend not on the specific implementations but only on the abstracts, on the interfaces.<\/p>\n<h2>Abstract and the interface<\/h2>\n<p>We should always treat the abstract classes and the interfaces as a solid and invariable element. When programming the system we should design the main interfaces and basing on them \u2013 build the correlation between the classes or modules. Each component of the system would then depend on the invariable elements.<\/p>\n<h2>Where does the name come from?<\/h2>\n<p>In order to understand well why the principle was named a dependency inversion one, it is good to take a look at the two charts below, mentioned previously during the\u00a0<a href=\"http:\/\/web.evertop.pl\/understanding-solid-principles-single-responsibility\/\">first project principle<\/a>\u00a0explanation:<\/p>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\"><\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img class=\"wp-image-2995\" src=\"https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe%C5%82-artyku%C5%82.png\" sizes=\"(max-width: 670px) 100vw, 670px\" srcset=\"https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe\u0142-artyku\u0142.png 670w, https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe\u0142-artyku\u0142-300x121.png 300w\" alt=\"\" \/><\/figure>\n<\/div>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\"><\/div>\n<p>We talked about a hypothetical\u00a0 module to manage the employees. To avoid the necessity of the whole system\u2019s modification we introduced then the fa\u00e7ade project prototype. The other elements of the system will still depend on that fa\u00e7ade though, which will again depend on the specific implementations: HourReporter, EmployeeSaver and PayCalculator. By introducing the new interfaces we will obtain the following chart:<\/p>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\"><\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img class=\"wp-image-2996\" src=\"https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe%C5%82-artyku%C5%822.png\" sizes=\"(max-width: 730px) 100vw, 730px\" srcset=\"https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe\u0142-artyku\u01422.png 730w, https:\/\/www.web.evertop.pl\/wp-content\/uploads\/pawe\u0142-artyku\u01422-300x140.png 300w\" alt=\"\" \/><\/figure>\n<\/div>\n<div class=\"wp-block-spacer\" aria-hidden=\"true\"><\/div>\n<p>The flow of the information will obviously remain the same. The direction of those dependencies will change though. It is shown on the picture by the inverted direction of the arrows, which represent the dependencies, and this inversion became the principle\u2019s name. Now the EmployeeFacade and HourReporter, EmployeeSaver and PayCalculator depend on the interfaces, which can be characterized by the significant level of invariability.<\/p>\n<h2>The significance to the architecture<\/h2>\n<p>The described principle is very useful during the creation of systems\u2019 architecture. As I mentioned before, it helps to introduce to the system the solid independent elements, which will affect the specific implementations, combining that way the classes (or even the modules) which are not strongly linked together. It also helps to draw the boundaries for the modules. Using the above chart one can determine the module line between the interfaces and their implementation. This way we will obtain the module responsible for managing the employee related operations, independent of any specific implementation of these operations (the left side) and the module responsible for very specific operations. This module will only have to provide a few methods of specified functionality, but without the indication of how it is supposed to be processed. Such a module can be easily improved and developed or even removed.<\/p>\n<h2>The summary<\/h2>\n<p>The Dependency Inversion Principle helps to create softly bonded classes. In the wider meaning it supports the design of system architecture, correlation between the modules and helps to establish the boundaries between them. Dear Reader, I hope that from now on the SOLID principles will be much more useful and understandable to you!<\/p>\n<p>&nbsp;<\/p>\n<p>Other SOLID principles:<br \/>\n<a href=\"http:\/\/web.evertop.pl\/understanding-solid-principles-single-responsibility\/\">Single Responsibility<\/a><br \/>\n<a href=\"http:\/\/web.evertop.pl\/understanding-solid-principles-open-closed\/\">Open-Closed<\/a><br \/>\n<a href=\"http:\/\/web.evertop.pl\/understanding-solid-principles-liskov-substitution\/\">Liskov Substitution<\/a><br \/>\n<a href=\"http:\/\/web.evertop.pl\/understanding-solid-principles-interface-segregation\/\">Interface Segregation<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the last article related to the set of SOLID project principles. The DIP principle is the most useful of all in terms of its relevance to the creation of strong classes and good architecture of the whole system. What can go wrong? When we create the classes or other code structures, they will [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1821,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[23,24,25],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Understanding SOLID Principles: Dependency Inversion - Evertop<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/\" \/>\n<meta property=\"og:locale\" content=\"nb_NO\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding SOLID Principles: Dependency Inversion - Evertop\" \/>\n<meta property=\"og:description\" content=\"This is the last article related to the set of SOLID project principles. The DIP principle is the most useful of all in terms of its relevance to the creation of strong classes and good architecture of the whole system. What can go wrong? When we create the classes or other code structures, they will [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/\" \/>\n<meta property=\"og:site_name\" content=\"Evertop\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/EvertopPoland\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-21T08:51:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-23T18:57:04+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/web.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1514\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Skrevet av\" \/>\n\t<meta name=\"twitter:data1\" content=\"Katarzyna Baron\" \/>\n\t<meta name=\"twitter:label2\" content=\"Ansl. lesetid\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutter\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.evertop.pl\/#organization\",\"name\":\"Evertop\",\"url\":\"https:\/\/www.evertop.pl\/\",\"sameAs\":[\"https:\/\/www.facebook.com\/EvertopPoland\/\",\"https:\/\/www.linkedin.com\/company\/evertop-software-development\/\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.evertop.pl\/#logo\",\"inLanguage\":\"nb-NO\",\"url\":\"https:\/\/www.evertop.pl\/wp-content\/uploads\/2021\/04\/logo_new.png\",\"contentUrl\":\"https:\/\/www.evertop.pl\/wp-content\/uploads\/2021\/04\/logo_new.png\",\"width\":582,\"height\":114,\"caption\":\"Evertop\"},\"image\":{\"@id\":\"https:\/\/www.evertop.pl\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.evertop.pl\/#website\",\"url\":\"https:\/\/www.evertop.pl\/\",\"name\":\"Evertop\",\"description\":\"we code the future\",\"publisher\":{\"@id\":\"https:\/\/www.evertop.pl\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.evertop.pl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"nb-NO\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage\",\"inLanguage\":\"nb-NO\",\"url\":\"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg\",\"contentUrl\":\"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg\",\"width\":2560,\"height\":1514},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage\",\"url\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/\",\"name\":\"Understanding SOLID Principles: Dependency Inversion - Evertop\",\"isPartOf\":{\"@id\":\"https:\/\/www.evertop.pl\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage\"},\"datePublished\":\"2020-10-21T08:51:06+00:00\",\"dateModified\":\"2020-10-23T18:57:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#breadcrumb\"},\"inLanguage\":\"nb-NO\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Strona g\\u0142\\u00f3wna\",\"item\":\"https:\/\/www.evertop.pl\/no\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Understanding SOLID Principles: Dependency Inversion\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage\"},\"author\":{\"@id\":\"https:\/\/www.evertop.pl\/#\/schema\/person\/8187ac3407cd931ed1a015a96990e2df\"},\"headline\":\"Understanding SOLID Principles: Dependency Inversion\",\"datePublished\":\"2020-10-21T08:51:06+00:00\",\"dateModified\":\"2020-10-23T18:57:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage\"},\"wordCount\":703,\"publisher\":{\"@id\":\"https:\/\/www.evertop.pl\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg\",\"keywords\":[\"programming tips\",\"self development\",\"SOLID\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"nb-NO\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.evertop.pl\/#\/schema\/person\/8187ac3407cd931ed1a015a96990e2df\",\"name\":\"Katarzyna Baron\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.evertop.pl\/#personlogo\",\"inLanguage\":\"nb-NO\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/208e27a58a39e5d96f459a4802804274?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/208e27a58a39e5d96f459a4802804274?s=96&d=mm&r=g\",\"caption\":\"Katarzyna Baron\"},\"url\":\"https:\/\/www.evertop.pl\/no\/author\/kbaron\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Understanding SOLID Principles: Dependency Inversion - Evertop","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/","og_locale":"nb_NO","og_type":"article","og_title":"Understanding SOLID Principles: Dependency Inversion - Evertop","og_description":"This is the last article related to the set of SOLID project principles. The DIP principle is the most useful of all in terms of its relevance to the creation of strong classes and good architecture of the whole system. What can go wrong? When we create the classes or other code structures, they will [&hellip;]","og_url":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/","og_site_name":"Evertop","article_publisher":"https:\/\/www.facebook.com\/EvertopPoland\/","article_published_time":"2020-10-21T08:51:06+00:00","article_modified_time":"2020-10-23T18:57:04+00:00","og_image":[{"width":2560,"height":1514,"url":"http:\/\/web.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg","path":"\/home\/evertop\/web-evertop\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg","size":"full","id":1821,"alt":"","pixels":3875840,"type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Skrevet av":"Katarzyna Baron","Ansl. lesetid":"3 minutter"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.evertop.pl\/#organization","name":"Evertop","url":"https:\/\/www.evertop.pl\/","sameAs":["https:\/\/www.facebook.com\/EvertopPoland\/","https:\/\/www.linkedin.com\/company\/evertop-software-development\/"],"logo":{"@type":"ImageObject","@id":"https:\/\/www.evertop.pl\/#logo","inLanguage":"nb-NO","url":"https:\/\/www.evertop.pl\/wp-content\/uploads\/2021\/04\/logo_new.png","contentUrl":"https:\/\/www.evertop.pl\/wp-content\/uploads\/2021\/04\/logo_new.png","width":582,"height":114,"caption":"Evertop"},"image":{"@id":"https:\/\/www.evertop.pl\/#logo"}},{"@type":"WebSite","@id":"https:\/\/www.evertop.pl\/#website","url":"https:\/\/www.evertop.pl\/","name":"Evertop","description":"we code the future","publisher":{"@id":"https:\/\/www.evertop.pl\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.evertop.pl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"nb-NO"},{"@type":"ImageObject","@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage","inLanguage":"nb-NO","url":"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg","contentUrl":"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg","width":2560,"height":1514},{"@type":"WebPage","@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage","url":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/","name":"Understanding SOLID Principles: Dependency Inversion - Evertop","isPartOf":{"@id":"https:\/\/www.evertop.pl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage"},"datePublished":"2020-10-21T08:51:06+00:00","dateModified":"2020-10-23T18:57:04+00:00","breadcrumb":{"@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#breadcrumb"},"inLanguage":"nb-NO","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Strona g\u0142\u00f3wna","item":"https:\/\/www.evertop.pl\/no\/"},{"@type":"ListItem","position":2,"name":"Understanding SOLID Principles: Dependency Inversion"}]},{"@type":"Article","@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#article","isPartOf":{"@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage"},"author":{"@id":"https:\/\/www.evertop.pl\/#\/schema\/person\/8187ac3407cd931ed1a015a96990e2df"},"headline":"Understanding SOLID Principles: Dependency Inversion","datePublished":"2020-10-21T08:51:06+00:00","dateModified":"2020-10-23T18:57:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#webpage"},"wordCount":703,"publisher":{"@id":"https:\/\/www.evertop.pl\/#organization"},"image":{"@id":"https:\/\/www.evertop.pl\/no\/understanding-solid-principles-dependency-inversion\/#primaryimage"},"thumbnailUrl":"https:\/\/www.evertop.pl\/wp-content\/uploads\/2020\/09\/pexels-startup-stock-photos-7103-scaled-1.jpg","keywords":["programming tips","self development","SOLID"],"articleSection":["Blog"],"inLanguage":"nb-NO"},{"@type":"Person","@id":"https:\/\/www.evertop.pl\/#\/schema\/person\/8187ac3407cd931ed1a015a96990e2df","name":"Katarzyna Baron","image":{"@type":"ImageObject","@id":"https:\/\/www.evertop.pl\/#personlogo","inLanguage":"nb-NO","url":"https:\/\/secure.gravatar.com\/avatar\/208e27a58a39e5d96f459a4802804274?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/208e27a58a39e5d96f459a4802804274?s=96&d=mm&r=g","caption":"Katarzyna Baron"},"url":"https:\/\/www.evertop.pl\/no\/author\/kbaron\/"}]}},"_links":{"self":[{"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/posts\/2120"}],"collection":[{"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/comments?post=2120"}],"version-history":[{"count":4,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/posts\/2120\/revisions"}],"predecessor-version":[{"id":2161,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/posts\/2120\/revisions\/2161"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/media\/1821"}],"wp:attachment":[{"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/media?parent=2120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/categories?post=2120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.evertop.pl\/no\/wp-json\/wp\/v2\/tags?post=2120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}