{"componentChunkName":"component---src-templates-blog-post-js","path":"/Depedency-Inversion/","result":{"data":{"site":{"siteMetadata":{"title":"Ibrahim personal blog","author":"Ibrahim"}},"markdownRemark":{"id":"d0760818-ca0b-5cbd-870c-417fe96fde36","html":"<p>Here we go 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀\nImagine what software development was like before a safe and convenient mechanism for polymorphism was available, it was manually handled via pointers in C and other old languages.</p>\n<h2 id=\"dependency-inversion\"><a href=\"#dependency-inversion\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Dependency Inversion</h2>\n<p>In the typical calling tree, main functions called high-level functions, which called mid-level functions, which called low-level functions. In that calling tree, however, source code dependencies inexorably followed the flow of control.</p>\n<h4 id=\"sounds-interesting\"><a href=\"#sounds-interesting\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Sounds interesting?</h4>\n<h5 id=\"but-lets-take-a-look-at-how-the-process-flows\"><a href=\"#but-lets-take-a-look-at-how-the-process-flows\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>But let’s take a look at how the process flows</h5>\n<p>Let’s say that the main function calls out high-level function,\nthe middle-level function acts as an interface for F(), however, that the source code dependency (the inheritance relationship)\nbetween ML1 and the interface, I point in the opposite direction compared to the flow of control. </p>\n<h4 id=\"the-fact-that-oo-languages-provide-safe-and-convenient-polymorphism-means-that-any-source-code-dependency-no-matter-where-it-is-can-be-inverted\"><a href=\"#the-fact-that-oo-languages-provide-safe-and-convenient-polymorphism-means-that-any-source-code-dependency-no-matter-where-it-is-can-be-inverted\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The fact that OO languages provide safe and convenient polymorphism means that any source code dependency, no matter where it is, can be inverted.</h4>\n<p>With this approach:nerd_face:, architects who working in systems written in OO languages have absolute control over the direction of all source code dependencies flow in the system. They are not constrained to align those dependencies with the flow of control they can add more dependencies as a sort of plugin thanks to polymorphism:heart:.</p>\n<h3 id=\"also-this-principle-makes-your-program-functionality-clear-and-agile\"><a href=\"#also-this-principle-makes-your-program-functionality-clear-and-agile\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Also this principle makes your program functionality clear and agile.</h3>\n<p>No matter which module does the calling and which module is called, the software architect can point the source code dependency in either direction.</p>\n<h5 id=\"that-is-power-that-is-the-power-that-oo-provides-thats-what-oo-is-really\"><a href=\"#that-is-power-that-is-the-power-that-oo-provides-thats-what-oo-is-really\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>That is power! That is the power that OO provides. That’s what OO is really.</h5>\n<p>All about at least from the architect’s point of view.\nWhat can you do with that power? As an example, you can rearrange the source code dependencies of your system so that the database and the user interface (UI) depend on the business rules, rather than the other way around.</p>\n<p>This means that the UI is the main function, the database and business logic can be plugins to the system’s rules. It means that the source code of the business rules never mentions the UI or the database.\nAnd this will help in software fast delivery.\nFor further check out the book of architecture called clean architecture by Robert-C,-Martin.</p>","timeToRead":2,"frontmatter":{"title":"What is depedency inversion","date":"July 05, 2019","spoiler":null,"tags":null},"fields":{"slug":"/Depedency-Inversion/","langKey":"en"}}},"pageContext":{"slug":"/Depedency-Inversion/","previous":{"fields":{"slug":"/Single-responsibilty/","langKey":"en","directoryName":"Single-responsibilty","maybeAbsoluteLinks":[]},"frontmatter":{"title":"the SRP principle"}},"next":{"fields":{"slug":"/SOLID-Principles/","langKey":"en","directoryName":"SOLID-Principles","maybeAbsoluteLinks":[]},"frontmatter":{"title":"The \"SOLID\" Principles in designing software"}},"translations":[],"translatedLinks":[]}}}