<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Wimal Perera on Medium]]></title>
        <description><![CDATA[Stories by Wimal Perera on Medium]]></description>
        <link>https://medium.com/@wimal-perera?source=rss-b1da499622a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*YBvNGr1gdzqQMFWwHkjxHA.jpeg</url>
            <title>Stories by Wimal Perera on Medium</title>
            <link>https://medium.com/@wimal-perera?source=rss-b1da499622a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:14:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wimal-perera/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Developing Agile-Driven Software whilst adhering with Best Engineering Practices]]></title>
            <link>https://medium.com/lexicon-digital/developing-agile-driven-software-whilst-adhering-with-best-engineering-practices-261a6aabe7a5?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/261a6aabe7a5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[code-refactoring]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 03:23:58 GMT</pubDate>
            <atom:updated>2020-12-02T02:00:22.613Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C0ohUlbG-VKnt3Sp6AwQyg.png" /></figure><p><strong><em>“Software Engineering”</em></strong> is different from most of the other engineering domains because;</p><ul><li>it takes <strong><em>“significantly large amount of time”</em></strong> (at least months or in some cases years) to design, develop and deploy <strong><em>“software”</em></strong>-based <strong><em>“IT (Information Technology) Systems”</em></strong></li><li><strong><em>“product requirements”</em></strong> of an <strong><em>“IT System”</em></strong> often <strong><em>“change from time to time during its entire life cycle”</em></strong> (i.e. during design, development and even after deployment)</li></ul><p>Hence <em>“software engineering”</em> needs to have its own set of <em>“endemic”</em> engineering practices in order to manage an engineered product (i.e. IT System) <em>“over a </em><strong><em>long time</em></strong><em> with constantly </em><strong><em>changing product requirements</em></strong><em>”</em>.</p><p>In order to facilitate <em>“software engineering”</em> for the above challenges, from a client/customer interfacing point of view; the <strong><em>“software development process”</em></strong> have evolved from the obsolete <strong><em>“waterfall methods”</em></strong> to the currently accepted <strong><em>“agile-scrum methods”</em></strong> over the last decade.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IHwfaZZ6VlbTyS3loSm4w.png" /><figcaption><strong>Figure 1: A “For Dummies” Illustration of Agile Software Process from a Sprint’s Perspective</strong></figcaption></figure><p>The <strong><em>“agile-driven software processes”</em></strong> focus on delivering a software by means of <strong><em>“potentially shippable product increments </em></strong><em>carrying new feature additions”</em> once every shorter time span (usually once a fortnight called a <strong><em>“sprint”</em></strong>) to the overall delivery. Hence the <em>“requirement changes”</em> (logged as “new or refined <strong><em>user stories</em></strong>”) are <em>“re-captured”</em> and <em>“re-prioritized”</em> during the start of every <em>“sprint”</em> and the <em>“overall design/architecture of the IT system”</em> is <em>“evolved”</em> based on the new requirements.</p><p>There exists a plethora of documentation in terms of capturing the changing customer requirements, refining requirements based on new changes, adjusting project goals in during an agile project delivery etc. However, there exist only abysmal amount of documentation explaining software developers on <strong><em>“how to evolve the design and architecture of an IT-system adhering with best engineering pratices, while catering the requirement changes arising during the agile software process ?”</em></strong>. The main goal of this article is to fill this missing literature, in which we go through our example software project <strong><em>“eMystery”</em></strong> starting from simple requirements in the initial sprint, in which later diversify into larger complex requirements after the end of each sprint during the progression of the project. During each sprint we will discuss about <strong><em>“how to evolve the design of the system based on new requirement changes while adhering with best software engineering practices”</em></strong>.</p><p>Please note that before reading the rest of this article, it is not mandatory, yet recommended to skim through the articles;</p><ol><li><a href="https://medium.com/lexicon-digital/inside-the-object-oriented-toolbox-mapping-between-design-implementation-405f00e22bd"><em>“Inside the Object-Oriented Toolbox — Mapping between Design &amp; Implementation”</em></a>, which provides an in-depth explanation of how you would map an <em>“OO Design”</em> presented in a <em>“UML class diagram”</em> to <em>“Java”</em> implementation code</li><li><a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c">“Inside the Object-Oriented Toolbox — Avoiding bad design with SOLID Principles”</a>, which describes on how to avoid bad practices in <em>“software design”</em> by applying <em>“OO SOLID principles”</em></li></ol><h3>Project eMystery — Sprint 1</h3><p>The requirements for our hypothetical <em>“eMystery”</em> project for <em>“Sprint 1”</em> are as below.</p><ul><li>Need an encryption service, which is able to provide an encrypted file for a given plain text file.</li><li>Encryption is done using DES encryption</li></ul><p>Let’s assume that, since the delivery deadline was tight and the requirements were too simple someone ended up implementing the below <strong><em>java</em></strong>-based solution which serves the purpose during <em>“Sprint 1”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYnePTEf0QBTHtmoGznOpw.png" /><figcaption><strong>Figure 2: EncryptionService after Sprint 1</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vqQNL-LH08_uPMvgDwTjcw.png" /><figcaption><strong>Figure 3: EncryptionService consumer class (BizClass) after Sprint 1</strong></figcaption></figure><p>Hence the simple design resulted after <em>“Sprint 1”</em> (according to the implementations presented in Figures 2 and 3); is as below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MqShMaVbLy7sZtjA5ACXA.png" /><figcaption><strong>Figure 4: Overall Design after Sprint 1</strong></figcaption></figure><p>Although this solution serves the requirements for <em>“Sprint 1”</em>, can you identify the design issues behind it?</p><p>The <strong><em>EncryptionService</em></strong> class violates <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Single Responsibility Principle (SRP)”</em></strong></a>. <strong><em>EncryptionService</em></strong> handles 4 responsibilities as below. (the first one is obvious, for 2, 3 and 4 have a look at the 3 regions of code circled in <em>“red”</em> in Figure 2)</p><ol><li>Exposing encryption as a service</li><li>Handling data retrieval based on different IO sources</li><li>Handling encryption based on different IO targets</li><li>Handling encryption based on different algorithms</li></ol><p>This design and implementation can be left as it is, if it is the end of the project and there are no more requirements to modify this module in future.</p><p>However the real problems arise due to the above design issue, when new requirements get added during <em>“Sprint 2”</em>.</p><h3>Project eMystery — Sprint 2</h3><p><em>“eMystery”</em> project’s requirement changes for <em>“Sprint 2”</em> are as below.</p><ul><li>Our encryption service, must support both DES and AES encryption algorithms</li></ul><p>However, since we have to live with existing code from <em>“Sprint 1”</em>, this section is going to discuss 2 possible solutions that could cater the above new requirement within our existing implementation during <em>“Sprint 2”</em>.</p><ol><li>Survival Solution</li><li>Best Practices Solution</li></ol><p><strong><em>Sprint 2 — Survival Solution</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zRz1lqWgyfn9a9mEcWvQqw.png" /><figcaption><strong>Figure 5 — Sprint 2, Survival Solution for the EncryptionService</strong></figcaption></figure><p>We call this as the <em>“Survival Solution”</em>, since it requires only several minor modifications on the code we have from <em>“Sprint 1” </em>with<em> “a very little effort” </em>(see Figures 5 and 6), still leaving the same design from <em>“Sprint 1”</em> (as in Figure 4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZIakvyaN_zKKLaeuOux3eA.png" /><figcaption><strong>Figure 6 — Sprint2, Survival Solution for the BizClass</strong></figcaption></figure><p>However from the <em>“engineering practices”</em> point of view, our <strong><em>EncryptionService </em></strong>class now violates <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Open Close Principle (OCP)”</em></strong></a> in addition to violating <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Single Responsibility Principle (SRP)”</em></strong></a> during <em>“Sprint 1”</em>. So we are going to see a solution which caters the requirement changes for <em>“Sprint 2”</em> and adhere with <em>“engineering practices”</em> the same time.</p><p><strong><em>Sprint 2 — Best Practices Solution</em></strong></p><p>We can move out the encryption part into a separate abstract class <strong><em>EncryptionAlgorithm</em></strong> as in Figure 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1nmPpeoqvtJO1Gd4hnwZQ.png" /><figcaption><strong>Figure 7 — Abstracting Content Encryption</strong></figcaption></figure><p>Then we introduce the <strong><em>EncryptionAlgorithmFactory </em></strong>(see Figure 8), so that we can extend our design with any number of different encryption algorithms in future adhering with the <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Open Close Principle (OCP)”</em></strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtJqSmM-BlodY5Qh6TvLtg.png" /><figcaption><strong>Figure 8 — Introducing a Factory</strong></figcaption></figure><p>Hence our new <strong>EncryptionService</strong> class will have the changes illustrated in Figure 9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLaLREZB2Qyx9-eZdhtL5g.png" /><figcaption><strong>Figure 9 — EncryptionService using the Abstraction of EncryptionAlgorithm</strong></figcaption></figure><p>As illustrated in Figure 9, introducing the <strong><em>EncryptionAlgorithm</em></strong> class has partially resolved the <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Single Responsibility Principle (SRP)”</em></strong></a> related issues from <em>“Sprint 1”</em>, since the content encryption responsibility is now moved into the <strong><em>EncryptionAlgorithm</em></strong> class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-ata_LLMjrDKg7QFZhVFg.png" /><figcaption><strong>Figure 10 — Modified BizClass consuming EncryptionAlgorithmFactory and EncryptionService</strong></figcaption></figure><p>Hence, with our <em>“Best Practices”</em> solution we’ve managed to achieve both; catering the requirement changes during <em>“Sprint 2”</em> and <em>“evolve”</em> the codebase into a better design adhering with software engineering practices (see Figure 11).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0i3ELEaFOK-5jx2Y1cKGw.png" /><figcaption><strong>Figure 11 — Evolved Design after Sprint 2, adhering with Engineering Practices</strong></figcaption></figure><h3>Project eMystery — Sprint 3</h3><p>For <em>“Sprint 3”</em>, the <em>“eMystery”</em> project has received the below requirement changes.</p><ul><li>The <strong>sources </strong>or <strong>targets</strong> (i.e. destinations) in the encryption service can either be files in the local hard drive, or a data set remotely accessible via a webservice.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5aJTXdfrPEAmHkcMLg3FQ.png" /><figcaption><strong>Figure 12 — Introducing IEntity to abstract Sources and Targets</strong></figcaption></figure><p>So for the solution, we start by upgrading the <strong><em>String</em></strong> values representing source and destination in <strong><em>EncryptionService</em></strong> (from <em>“Sprint 2”</em>) to <strong><em>IEntity</em></strong> abstraction (see Figures 12 and 13). The main rationale behind this approach is to;</p><ol><li>Make sources and destinations independent from <strong><em>EncryptionService</em></strong> based on <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>Dependency Inversion Principle (DIP)</em></strong></a> <strong>AND</strong></li><li>Divert away the remaining additional responsibilities of the <strong><em>EncryptionService</em></strong> class to make the overall design adhere with <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>Single Responsibility Principle (SRP)</em></strong></a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wgqTdtPaGlRDR1F0i1Aybw.png" /><figcaption><strong>Figure 13 — IEntity Abstraction</strong></figcaption></figure><p>Our <strong><em>BizClass</em></strong> will be modified as illustrated in Figure 14, in order to support the <strong><em>IEntity</em></strong> abstraction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zOs3q43zZ0eTS9rRxv4hIw.png" /><figcaption><strong>Figure 14 — BizClass consuming IEntity</strong></figcaption></figure><p>Hence the overall <em>“evolved”</em> design of the whole system will be identical to what is illustrated in Figure 15.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Tkz_uHdtQB8fL4PBpO1IQ.png" /><figcaption><strong>Figure 15 — “Evolved” System Design after “Sprint 3”</strong></figcaption></figure><h3><strong>Project eMystery — Sprint 4</strong></h3><p>Here comes the requirement changes just before commencing Sprint 4 for eMystery.</p><ul><li><strong>Wireless Connections </strong>will <strong>ONLY</strong> act as <strong>sources</strong> for the encryption service</li></ul><p>The quickest solution would be to introduce the <strong><em>WirelessConnection</em></strong> class as in Figure 16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oujJxC7utJRCxffS03RmBA.png" /><figcaption><strong>Figure 16 — WirelessConnection class implementing IEntity</strong></figcaption></figure><p>However this solution has a pitfall, since it violates <a href="https://medium.com/the-innovation/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c"><strong><em>“Interface Segregation Principle (ISP)”</em></strong></a>. The reason is that with the new requirement for <strong><em>WirelessConnection</em></strong> introduced in <em>“Sprint 4”</em>, all <strong><em>IEntity</em></strong> instance types <strong>DOES NOT</strong> need to act as both, sources and targets. Some <strong><em>IEntity</em></strong> types can only act as sources. Hence <strong><em>IEntity</em></strong> has become a <em>“fatty”</em> interface in our system.</p><p>Hence a better solution would be to split the <em>“fatty”</em> <strong><em>IEntity</em></strong> interface into 2 smaller interfaces; <strong><em>ISource</em></strong> and <strong><em>ITarget</em></strong> (see Figure 17).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZxSb2gfdsJM_VoTgEqYTyQ.png" /><figcaption><strong>Figure 17 — ISource and ITarget</strong></figcaption></figure><p>We can write the <strong><em>WirelessConnection</em></strong> class, by only implementing from the <strong><em>ISource</em></strong> interface (see Figure 18).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLNltJQlbPGED2FjXy4p_g.png" /><figcaption><strong>Figure 18 — WirelessConnection implementing ISource</strong></figcaption></figure><p>Hence our <strong><em>EncryptionService</em></strong> will have the new modifications as illustrated in Figure 19.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OWEMGPI-y0lNZrTQM-nrgQ.png" /><figcaption><strong>Figure 19 — EncryptionService with ISource and ITarget</strong></figcaption></figure><p>Finally our <strong><em>BizClass</em></strong> will consume ISource and ITarget as illustrated in Figure 20.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UsURHEWmK64JSS__2vduAg.png" /><figcaption><strong>Figure 20 — BizClass consuming ISource and ITarget</strong></figcaption></figure><p>The overall design of the system at the end of <em>“Sprint 4”</em>, will be identical to Figure 21.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-PsruT1S7jgzf4qlR7Uiw.png" /><figcaption><strong>Figure 21 — “Evolved” System Design after “Sprint 4”</strong></figcaption></figure><h3>Conclusion</h3><p>Hence with the nature of the requirement pipeline in an Agile-Driven environment, the features of a system could always <em>“evolve”</em>, with the continuously changing requirements. However, <em>“careful refactoring”</em> of the system design and implementation adhereing with <em>“best engineering practices”</em> similar to the simple walkthrough we underwent in this blog across 4 <em>“sprints”</em> will aid the developers to still maintain the quality of the software product whilst catering Agile-driven requirements during every sprint.</p><p>Interested in taking that initial step in improving your business by designing and developing a value-driven IT system with best Agile software practices? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=261a6aabe7a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lexicon-digital/developing-agile-driven-software-whilst-adhering-with-best-engineering-practices-261a6aabe7a5">Developing Agile-Driven Software whilst adhering with Best Engineering Practices</a> was originally published in <a href="https://medium.com/lexicon-digital">Lexicon Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inside the Object-Oriented Toolbox — Avoiding bad design with SOLID Principles]]></title>
            <link>https://wimal-perera.medium.com/inside-the-object-oriented-toolbox-avoiding-bad-design-with-solid-principles-b8eb256c968c?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8eb256c968c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[uml]]></category>
            <category><![CDATA[oo-design]]></category>
            <category><![CDATA[software-design]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Sun, 12 Jul 2020 11:16:18 GMT</pubDate>
            <atom:updated>2020-07-26T01:14:23.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7T_MQ8cFP1TgKBkf8dDWeg.jpeg" /></figure><h3>Inside the Object-Oriented Toolbox — Avoiding bad design with SOLID Principles</h3><p>Although <strong><em>“Object-Oriented (OO) Programming”</em></strong> is used to achieve reusable, extendable, and maintainable software systems; some of the program logic created based on <em>“OO Design”</em> often end up as highly coupled, monolithic software implementations. While investigating the key reasons behind this dilemma, it can be often observed that <em>“bad OO implementations”</em> (i.e. OO program logic) emerge as a result of <em>“misusing core OO concepts”</em> (i.e. <em>“Abstraction”</em>, <em>“Encapsulation”</em>, <em>“Inheritance”</em> and <em>“Polymorphism”</em>) during software design.</p><p>Hence OO Theory is extended with <strong><em>“SOLID principles”</em></strong>, by providing a set of guidelines in order <em>“to avoid a bad OO Design”</em>.</p><ul><li><strong>S</strong>ingle Responsibility Principle (SRP)</li><li><strong>O</strong>pen Close Principle (OCP)</li><li><strong>L</strong>iskov’s Substitution Principle (LSP)</li><li><strong>I</strong>nterface Segregation Principle (ISP)</li><li><strong>D</strong>ependency Inversion Principle (DIP)</li></ul><p>The main focus of this article is to explain the practical usage of each SOLID principle, by providing a <em>“bad OO design example”</em> followed by its <em>“rectified OO design” </em>(<em>“Java”</em> is used as the implementation language for all the provided code examples).</p><p>Please note that before reading the rest of this article, it is not mandatory, yet recommended to of have skimmed through the article; <a href="https://medium.com/lexicon-digital/inside-the-object-oriented-toolbox-mapping-between-design-implementation-405f00e22bd"><em>“Inside the Object-Oriented Toolbox — Mapping between Design &amp; Implementation”</em></a>, which provides an in-depth explanation of how you would map an <em>“OO Design”</em> presented in a <em>“UML class diagram”</em> to <em>“Java”</em> implementation code.</p><h3>Single Responsibility Principle (SRP)</h3><p>SRP states that, <em>“a class should have ONLY </em><strong><em>one reason</em></strong><em> to </em><strong><em>change</em></strong><em>”.</em></p><p>Consider the design provided in Figure 1 and its corresponding implementation in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KG5uyo9ZN0blBW0R-GuCgg.png" /><figcaption><strong>Figure 1 — Email: Design Example before applying SRP</strong></figcaption></figure><p>By looking at the design and implementation in Figure 1 and Figure 2, we can observe that the <em>“Email”</em> class has at least 2 reasons to change (in other words the <em>“Email”</em> class handles 2 responsibilities).</p><ul><li>Assembling an email by combining its meta data (sender, receiver etc.) and the body content</li><li>Parsing/Formatting email body content (html, richText etc.)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5omao3Gt4iwmeKEjsPwdgg.png" /><figcaption><strong>Figure 2 — Email: Java Code before applying SRP</strong></figcaption></figure><p>Below are some of the side effects that could occur due to maintaining 2 <em>“responsibilities”</em> (i.e. 2 <em>“reasons to change”</em>) within the <em>“Email”</em> class.</p><ul><li>We need to change the implementation inside the <em>“Email”</em> class, when introducing a new content type (like xml, excel etc.)</li><li>What if there were multiple implementations of <em>“IEmail”</em> interface (Outlook, Gmail etc.) and a new content type has to be introduced? Are we going to change all implementations of <em>“IEmail”</em>?​</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9mFQMrOz3GQGIMq3ZrOsQ.png" /><figcaption><strong>Figure 3 — Email: Design Example after applying SRP</strong></figcaption></figure><p>By adhering with SRP we split the 2 responsibilities of the <em>“Email”</em> class from previous design (Figure 1 and Figure 2), by creating 2 different classes in the new design (Figure 3 and Figure 4).</p><ul><li><em>“Email”</em> — Assembles the email with its meta data and body content</li><li><em>“HtmlContent”</em> — Parses/Formats html based email content</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dg9UTrZykqdMoVm5X4dGww.png" /><figcaption><strong>Figure 4 — Email: Java Code after applying SRP</strong></figcaption></figure><p>Note that since we have a separate interface <em>“IContent”</em> (see Figure 3) to decouple the content type from the <em>“IEmail”</em> and <em>“Email”</em>; the implementation code in the <em>“Email”</em> class can evolve independently irrespective of the content type.</p><h3>Open Close Principle (OCP)</h3><p>OCP states that, <em>“software entities like classes, modules and functions should be </em><strong><em>open for extension</em></strong><em> but </em><strong><em>closed for modifications</em></strong><em>”</em>.​</p><p>Consider the below design and implementation (Figure 5 and Figure 6) for an <em>“area calculator”</em> which calculates the area of a circle and a rectangle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeVH_AY_U87hhPM-PmVwhg.png" /><figcaption><strong>Figure 5 — Area Calculator: Design Example before applying OCP</strong></figcaption></figure><p>By looking at the design and implementation in Figure 5 and Figure 6; what would happen to code inside the <em>“AreaCalculator”</em> class (see Figure 6), if you introduced another new shape (such as ellipse)? Obviously the code inside the <em>“AreaCalculator”</em> class (see Figure 6) has to be modified with another <em>“conditional if statement”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAOh0elS-ZA47uAdcNtc6Q.png" /><figcaption><strong>Figure 6 — Area Calculator: Java Code before applying OCP</strong></figcaption></figure><p>Thus the <em>“AreaCalculator”</em> violates OCP since its implementation is closed for extensions without being modified upon introducing new shapes.</p><p>One possible solution to fix the <em>“AreaCalculator”</em> class by applying OCP, is to introduce a new abstract class <strong><em>“Shape”</em></strong> and decouple the <em>“AreaCalculator”</em> with the <em>“Circle”</em> and the <em>“Rectangle”</em> (see Figure 7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NO1Ia3_L0VO5PR4NR6fqNQ.png" /><figcaption><strong>Figure 7 — Area Calculator: Design Example after applying OCP</strong></figcaption></figure><p>As illustrated in Figure 8, the new implementation adhering to the OCP based design (in Figure 7) <strong><em>allows extensions</em></strong> since we can introduce more and more different shapes (like ellipse) <strong><em>without modifying</em></strong> the code inside the <em>“AreaCalculator”</em> class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xMevpJMNM1NQC3-h0REeNA.png" /><figcaption><strong>Figure 8 — Area Calculator: Java Code after applying OCP</strong></figcaption></figure><h3>Liskov’s Substitution Principle (LSP)</h3><p>LSP states that, <em>“derived types must be </em><strong><em>completely substitutable</em></strong><em> for their base types”</em>.</p><p>Consider the initial design for a <em>“FlightSimulator”</em> (Figure 9) illustrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pr1JPW8tfem5w45hT_4pJg.png" /><figcaption><strong>Figure 9 — Flight Simulator: Design Example before applying LSP</strong></figcaption></figure><p>What if an <em>“Ostrich”</em> is passed to the list of <em>“Birds”</em> in the code inside the <em>“FlightSimulator”</em> class (see Figure 10)? <em>“flyAllBirds()”</em> method is going to crash since an <em>“Ostrich”</em> can’t fly. The reason behind this code failure is that the <em>“Bird”</em> type is <strong><em>not completely substitutable</em></strong> for the code inside the <em>“FlightSimulator”</em>, since there are <em>“Birds”</em> like <em>“Ostriches”</em> that can’t fly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlRrsh95l-8uM0f3NO9lkw.png" /><figcaption><strong>Figure 10 — Flight Simulator: Java Code before applying LSP</strong></figcaption></figure><p>We can fix the <em>“flyAllBirds()”</em> issue (in Figure 9 and Figure 10) by slightly modifying our <em>“FlightSimulator”</em> design (see Figure 11), while introducing the <strong><em>completely substitutable</em></strong> <em>“FlightBird”</em> class into the middle of the class hierarchy (i.e. by applying LSP).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZPiRJmtiv_ZYa4wjYjXvg.png" /><figcaption><strong>Figure 11 — Flight Simulator: Design Example after applying LSP</strong></figcaption></figure><p>Hence, introducing the new <em>“FlightBird”</em> type to the input list of <em>“flyAllBirds()” </em>method in the <em>“FlightSimulator”</em> class fixes the design issue (Figure 12) since <em>“Ostriches”</em> are <em>“NonFlightBirds”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2t9dxSgJdpuW2_hiXQU8A.png" /><figcaption><strong>Figure 12 — Flight Simulator: Java Code after applying LSP</strong></figcaption></figure><h3>Interface Segregation Principle (ISP)</h3><p>ISP states that, <em>“clients should </em><strong><em>NOT</em></strong><em> be forced to depend upon interfaces that they </em><strong><em>DON’T</em></strong><em> use”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1TDp36-lrGlIlHoZl0w1FA.png" /><figcaption><strong>Figure 13 — Communication System: Design Example before applying ISP</strong></figcaption></figure><p>Consider the initial design of a communication system illustrated above (Figure 13).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W7vnbrPVA6pJSd6D4RuNnw.png" /><figcaption><strong>Figure 14 — Communication System: Java Code before applying ISP</strong></figcaption></figure><p>As per the design in Figure 13, although we have selected <em>“IContact”</em> as the common interface type to represent all contacts in the system against the contact name; by looking at the code in Figure 14 (written based on the design in Figure 13) we can note the below issues:</p><ul><li>The <em>“PhoneContact”</em> class does not require methods other than <em>“getName()”</em> and <em>“getTelephone()”</em>. But it <strong><em>has to leave other method stubs</em></strong> coming from the <em>“IContact”</em> interface as <strong><em>dummy empty implementations</em></strong>.</li><li>Although the <em>“Dialler”</em> class does not require methods other than <em>“getName()”</em> and <em>“getTelephone()”</em>, it <strong><em>has access to unwanted methods</em></strong> such as <em>“getEmailAddress()”</em>; since <em>“IContact”</em> is the parameter type representing contact details in the <em>“makeCall()”</em> method.</li><li>The <em>“EmailContact”</em> class does not require methods other than <em>“getName()”</em> and <em>“getEmailAddress()”</em>. But it <strong><em>has to leave other method stubs</em></strong> coming from the <em>“IContact”</em> interface as <strong><em>dummy empty implementations</em></strong>.</li><li>Although the <em>“Emailer”</em> class does not require methods other than <em>“getName()”</em> and <em>“getEmailAddress()”</em>, it <strong><em>has access to unwanted methods</em></strong> such as <em>“getTelephone()”</em>; since <em>“IContact”</em> is the parameter type representing contact details in the <em>“sendMessage()”</em> method.</li></ul><p>The main reason behind all the above 4 problems is due to <em>“IContact”</em> being a <strong><em>“fatty”</em></strong> interface, containing a method set in which most of its implementation classes (such as <em>“EmailContact”</em> and <em>“PhoneContact”</em>) <strong><em>require only a subset</em></strong> of the total method set. Thus the classes, <em>“EmailContact”</em> and <em>“PhoneContact”</em> are <strong><em>forced to depend upon</em></strong> the <strong><em>“fatty”</em></strong> <em>“IContact”</em> interface containing certain methods that they don’t use. Therefore the <em>“IContact”</em>-based design violates ISP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rx3zEXNdMmD2wfwd7AsqcA.png" /><figcaption><strong>Figure 15 — Communication System: Design Example after applying ISP</strong></figcaption></figure><p>The solution to avoid the <em>“IContact”</em> <strong><em>fatty</em></strong> interface, is to introduce the new <em>“IDiallable”</em>, <em>“IEmailable”</em> and <em>“IPostable”</em> interface types, each containing a subset of methods from <em>“IContact”</em> (see Figure 15).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FszqRpQNzaGqErhrprfILA.png" /><figcaption><strong>Figure 16 — Communication System: Java Code after applying ISP</strong></figcaption></figure><p>As illustrated in Figure 16 the implementation code based on the new ISP-based design has the characteristics described below.</p><ul><li>Unlike in Figure 14, the <em>“PhoneContact”</em> class <strong><em>does not have any unwanted empty method stubs</em></strong> since it implements the <strong><em>non-fatty</em></strong> <em>“IDiallable”</em> interface type.</li><li>Unlike in Figure 14, the <em>“Dialler”</em> class now has access to its <strong><em>essential methods only</em></strong>, since <em>“IDiallable”</em> is the parameter type representing contact details in the <em>“makeCall()”</em> method.</li><li>Unlike in Figure 14, the <em>“EmailContact”</em> class <strong><em>does not have any unwanted empty method stubs</em></strong> since it implements the <strong><em>non-fatty</em></strong> <em>“IEmailable”</em> interface type.</li><li>Unlike in Figure 14, the <em>“Emailer”</em> class now has access to its <strong><em>essential methods only</em></strong>, since <em>“IEmailable”</em> is the parameter type representing contact details in the <em>“sendMessage()”</em> method.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvHLbueRHvBcmtH8CVPSeA.png" /><figcaption><strong>Figure 17 — Communication System: Versatile Contacts after applying ISP</strong></figcaption></figure><p>Considering a single class can implement multiple interfaces, the new ISP-based design (described in Figure 15 and Figure 16), allows us to implement versatile contacts having phone, address and email altogether (see <em>“CompleteContact”</em> class in Figure 17) that can be reused across <em>“Dialler”</em> and <em>“Emailer”</em> implementations.</p><h3>Dependency Inversion Principle (DIP)</h3><p>DIP states that,</p><ul><li><em>“High-level modules”</em> <strong><em>should not depend</em></strong> on <em>“Low-level modules”</em>. Both <strong><em>should depend</em></strong> on <strong><em>“Abstractions”</em></strong>.​</li><li><strong>“Abstractions”</strong> <em>should not depend</em> on <strong>“Details”</strong>. <strong>“Details”</strong> <em>should depend</em> on <strong>“Abstractions”</strong>.​</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*6F4irw6PS3spndVB-AXcBw.png" /><figcaption><strong>Figure 18 — Bank Money Transfer: Design Example before applying DIP</strong></figcaption></figure><p>Figure 18 and Figure 19, illustrates an initial design and corresponding implementation for transferring money between 2 bank accounts. <em>“TransferManager”</em> is the <em>“high-level module”</em> and <em>“BankAccount”</em> is the <em>“low-level module”</em>; since <em>“TransferManager”</em> accesses the methods of <em>“BankAccount”</em> within its code. An implementation change of the <em>“BankAccount”</em> class will directly affect the <em>“TransferManager”</em> class. In other words the <em>“high-level module”</em> <em>“TransferManager”</em>, <strong><em>significantly</em></strong> depends on the <em>“low-level module”</em> <em>“BankAccount”</em>, which is a violation of DIP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d626GdlQUY3leEjOaXdo4g.png" /><figcaption><strong>Figure 19 — Bank Money Transfer: Java Code before applying DIP</strong></figcaption></figure><p>The <em>“DIP-based solution”</em> to remove the tight coupling between <em>“TransferManager”</em> and <em>“BankAccount”</em> classes is to introduce 2 <em>“abstractions”</em> (i.e. java interfaces), <em>“ITransferSource”</em> and <em>“ITransferDestination”</em> (see Figure 20 and Figure 21).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3roPJwxlfjCO1sVBKUYJpw.png" /><figcaption><strong>Figure 20 — Bank Money Transfer: Design Example after applying DIP</strong></figcaption></figure><p>Since both <em>“TransferManager”</em> and <em>“BankAccount”</em> modules now <strong><em>depend only on the 2 abstractions</em></strong> <em>“ITransferSource”</em> and <em>“ITransferDestination”</em>; the implementations of <em>“TransferManager”</em> and <em>“BankAccount”</em> classes can now <strong><em>freely evolve independently from each other</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Qb45fEnr-geHWqwGFmDDw.png" /><figcaption><strong>Figure 21 — Bank Money Transfer: Java Code after applying DIP</strong></figcaption></figure><p>Further as illustrated in Figure 20 and Figure 21, in the <em>“DIP-based design”</em> the <em>“abstractions”</em> (i.e. <em>“ITransferSource”</em> and <em>“ITransferDestination” </em>interface types) are <strong><em>independent</em></strong> from <em>“details”</em> (i.e. <em>“TransferManager”</em> and <em>“BankAccount” </em>classes) whereas the <em>“detail”</em> classes <strong><em>depend on</em></strong> <em>“abstractions”</em>; since <em>“ITransferSource”</em> and <em>“ITransferDestination”</em> are used within the implementation code of <em>“TransferManager”</em> and <em>“BankAccount”</em> classes.</p><p>It is also worth to note that the <strong><em>“Dependency Injection Pattern”</em></strong> (initially introduced by the <a href="https://spring.io/"><em>“Spring Framework”</em></a> and also abbreviated as <em>“DIP”</em>) is a <strong><em>practical application</em></strong> of the <em>“Dependency Inversion Principle”</em>.</p><h3>Conclusion</h3><p>Congratulations! you’re up to the final section of this <em>“SOLID Principles”</em> article. Having reached this point, it is worth to discuss about the high level relationship between <em>“OOP Concepts”</em> (<em>“Abstraction”</em>, <em>“Encapsulation”</em>, <em>“Inheritance”</em> and <em>“Polymorphism”</em>), <em>“SOLID Principles”</em> and <a href="https://www.dofactory.com/net/design-patterns"><em>“OO Design Patterns”</em></a> (23 design patterns introduced by the <em>“Gang-Of-Four”</em>) within the Object-Oriented literature (see Figure 22).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IvpRRCW6-JYVde6nxOicUQ.png" /><figcaption><strong>Figure 22 — OOP Overview</strong></figcaption></figure><p>As illustrated in Figure 22,</p><ul><li><em>“OO Concepts”</em> focus on the theoretical aspect within the <strong><em>spectrum</em></strong> of OO literature.</li><li><em>“SOLID Principles”</em> (inspired from the basic 4 <em>“OO Concepts”</em>; <em>“Abstraction”</em>, <em>“Encapsulation”</em>, <em>“Inheritance”</em> and <em>“Polymorphism”</em>) are both into theory and practice, instructing how to use the <em>“OO Concepts”</em> properly and avoid a bad OO design.</li><li><a href="https://www.dofactory.com/net/design-patterns"><em>“Gang-Of-Four”</em> (GoF) <em>“OO Design Patterns”</em></a> (inspired by both <em>“OO Concepts”</em> and <em>“SOLID Principles”</em>) are at the practical end of the OO literature spectrum.</li></ul><p>Having read the entirety of this blog, you’re now in a much better position to apply the basic <em>“OO Concepts”</em> and understanding <a href="https://www.dofactory.com/net/design-patterns"><em>“OO Design Patterns”</em></a> in true depth.</p><p>Interested in taking that initial step in improving your business by designing and developing a value-driven IT system? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8eb256c968c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inside the Object-Oriented Toolbox— Mapping between Design & Implementation]]></title>
            <link>https://medium.com/lexicon-digital/inside-the-object-oriented-toolbox-mapping-between-design-implementation-405f00e22bd?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/405f00e22bd</guid>
            <category><![CDATA[class-diagram]]></category>
            <category><![CDATA[uml-diagrams]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[uml]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 12:26:43 GMT</pubDate>
            <atom:updated>2020-07-11T08:27:39.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uzNCmfK_uGQLa-UZ8oemwg.png" /></figure><p><strong><em>“Object-Oriented Programming”</em></strong> has become the most popular design paradigm in the software industry nowadays, due to its capabilities behind producing reusable, customisable and maintainable code. However once a large domain is divided into separate <strong><em>“class”</em></strong>es (a <em>“class”</em> is the <em>“blueprint used to create an object”</em> during runtime) the application code is often scattered across multiple <em>“class”</em>-based program code files; making it difficult to visualize the overall design of the software system.</p><p>One solution that the programmers use to visualize the overall design of an <em>“Object-Oriented”</em>-based software system is to draw a <strong><em>“design diagram”</em></strong> illustrating all of its <em>“class”</em>es and <em>“different types of relationships”</em> between them. <strong><em>“UML Class Diagram”</em></strong> is the most popular type of the <em>“design diagram”</em> used for this purpose (see Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R4ccPXW1BSS4BkX_0WwRJA.png" /><figcaption><strong>Figure 1 — A Sample UML Class Diagram for a Hospital Management System</strong></figcaption></figure><p>Although there exists a plethora of internet literature explaining about <em>“Object-Oriented Programming”</em>, <strong><em>“UML”</em></strong> (Unified Modelling Language) and <em>“UML Class Diagrams”</em>; there exists only little literature explaining <em>“how to map a UML Class Diagram to the actual implementation code of a selected programming language”</em>. The main focus of this article is to contribute towards fulfilling this missing <em>“Design Mapping Literature”</em> by using <em>“java”</em> as the selected implementation language.</p><h3>Mapping a Single Class</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BTtXTCXMzE_h2h69qwx82A.png" /><figcaption><strong>Figure 2 — Mapping a single “Class” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Figure 2 illustrates how you could map a <em>“design class”</em> in a <em>“UML class diagram”</em> to a <em>“java”</em>-based <em>“implementation class”</em>. Note that our <em>“class”</em> in Figure 2 has the below characteristics.</p><ul><li>The name of the class is <em>“Person”</em></li><li><em>“name”</em> is a <em>“private attribute”</em> of the <em>“Person”</em> class</li><li><em>“getName()”</em> and <em>“setName()”</em> are <em>“public methods”</em> of the <em>“Person”</em> class</li><li><em>“populateJobDescription()”</em> is a <em>“protected method”</em> of the <em>“Person”</em> class</li></ul><h3>UML Class Diagram Relationship Types</h3><p>Now that we’ve covered how to map an isolated <em>“class”</em>, it’s time to discuss the different types of <em>“relationship”</em>s that could exist between 2 <em>“class”</em>es in a <em>“UML class diagram”</em>. Note that the below is a list of different relationship types that could exist between 2 classes, <em>“ordered from the weakest to the strongest”</em> in terms of the <em>“strength of the relationship”</em>.</p><ol><li>Dependency</li><li>Association</li><li>Aggregation</li><li>Composition</li><li>Generalization</li></ol><p>In addition to the above 5 relationship types, <em>“Realization”</em> is a special relationship that exists between a <em>“class”</em> and an <em>“interface”</em>. Note that unlike a class, an <em>“interface”</em> contains <em>“only the specification, but not the implementation”</em>.</p><h3>Dependency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F5CZ6N8giJQD51C-xrjh8g.png" /><figcaption><strong>Figure 3— Mapping a “Dependency” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Class <em>“A”</em> is <em>“dependent”</em> on another class <em>“B”</em> (note the direction of the arrow in Figure 3), if <em>“A”</em> is <em>“using B inside A’s implementation”</em> in one or more of the following cases.</p><ul><li>Case 1 — class “A” has at least a single method that returns class “B”</li><li>Case 2 — class “A” has at least a single method that has class “B” in at least one of its method arguments</li><li>Case 3 — class “A” has at least a single method that uses a “reference” of class “B” inside its method implementation</li></ul><h3>Association</h3><p>When <em>“class A has an association with class B”</em> it is stronger than a dependency, since class <em>“A”</em> is able to;</p><ul><li>maintain <em>“attributes”</em> of class <em>“B”</em> inside class <em>“A”</em> <strong>AND</strong></li><li>directly invoke <em>“methods of class B”</em> inside <em>“class A’s implementation”</em></li></ul><p>Association relationships can appear inside UML class diagrams in many different flavours.</p><p><strong><em>Uni-Directional Association</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qASdJtj81yRA0-sxQj_sDw.png" /><figcaption><strong>Figure 4 — Mapping a “Uni-Directional Association” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p><strong><em>Association with Multiplicity</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DzKRUowMXwjt2K7WZb6z_A.png" /><figcaption><strong>Figure 5 — Mapping an “Association with Multiplicity” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p><strong><em>Bi-Directional Association</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NuqL4XHLYnAluLkoHclaWg.png" /><figcaption><strong>Figure 6 —Mapping a “Bi-Directional Association” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p><strong><em>Reflexive Association</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15eMdGnhi5C_ug7fmgCH9A.png" /><figcaption><strong>Figure 7 — Mapping a “Reflexive Association” from “UML Design” to “Java Implementation”</strong></figcaption></figure><h3>Aggregation</h3><p>When <em>“class A has an aggregation with class B”</em> it is <em>“stronger than an association”</em>.</p><p>Class “A” has an <em>“aggregation”</em> relationship with class “B” if;</p><ul><li><em>“class A </em><strong><em>has</em></strong><em> an instance of class B”</em> <strong>BUT</strong></li><li>still <em>“an object made from B </em><strong><em>can exist on its own</em></strong><em> even after its corresponding A-based object is being disposed”</em></li></ul><p>Our example in Figure 8 illustrates (<em>“Class A”</em> -&gt; “Car” &amp; <em>“Class B”</em> -&gt; “StereoSystem”) one possible approach in which you could map an <em>“aggregation”</em> relationship modelled between 2 classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtP_ly7B7IFIw3wfQvgJ7Q.png" /><figcaption><strong>Figure 8 — Mapping an “Aggregation” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Note that the following are the possible business requirements behind bumping up the relationship between a Car and a StereoSystem from an association to an aggregation.</p><ul><li>A stereo system can be sold separately without a car (note the <em>“default constructor”</em> inside the <em>“StereoSystem”</em> class).​</li><li>A car can be sold separately without a stereo system (note the <em>“default constructor”</em> inside the <em>“Car”</em> class).​</li><li>If a car is bundled with a stereo system both need to be sold together.​</li><li>If a stereo system is broken after the purchase, the car can still be used.</li><li>If the car is broken after the purchase, the stereo system can still be used.</li></ul><h3>Composition</h3><p>When <em>“class A has a composition with class B”</em> it is <em>“stronger than an aggregation”</em>.</p><p>Class “A” has a <em>“composition”</em> relationship with class “B” if;</p><ul><li><em>“class A </em><strong><em>has</em></strong><em> an instance of class B”</em> <strong>AND</strong></li><li><em>“an object made from B </em><strong><em>CANNOT exist on its own</em></strong><em> after its corresponding A-based object is being disposed”</em></li></ul><p>Our example in Figure 9 illustrates (<em>“Class A”</em> -&gt; “Engine” &amp; <em>“Class B”</em> -&gt; “Piston”) one possible approach in which you could map a <em>“composition”</em> relationship modelled between 2 classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjKxJV_-4cLHUF-qMmdqwg.png" /><figcaption><strong>Figure 9 — Mapping a “Composition” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Note that the following are the possible business requirements behind bumping up the relationship between an Engine and a Piston from an association/aggregation to a composition.</p><ul><li>Every Engine <strong>MUST</strong> have a Piston.</li><li>We don’t sell pistons separately, we only sell engines.​ Thus there can’t be a piston separately sold without an engine.​</li><li>If an engine is broken due to some internal error (even other THAN in the PISTON), then customer has to buy (or exchange with) a NEW engine from us bundled with its own piston.</li><li>If the piston is broken and can’t be repaired, the customer has to buy (or exchange) a NEW engine (having its own Piston) from us, since the engine won’t work without the piston.</li></ul><p>If the business requirement related with determining the relationship between the Engine and the Piston were less constrained as below, we could have still modelled the Engine&lt;-&gt;Piston relationship as a <em>“less constrained aggregation”</em>, instead of a composition.</p><ul><li>Our inventory sells pistons separately, thus a piston can exist without an engine​​.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5iKjdFEZrVYef8dmSEbkA.png" /><figcaption><strong>Figure 10 — Mapping a “Composition” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Another popular example used to explain composition is Person and IdentityInformation (see Figure 10), since in most of the software systems;</p><ul><li>Each <em>“person”</em> MUST have his/her own <em>“identity information”</em></li><li>It is pointless to enter <em>“identity information”</em> to a system without a reference to a <em>“person”</em></li></ul><p>Note that some of the existing UML literature refers both “aggregation” and “composition” relationships as <strong><em>“HAS A”</em></strong> relationships.</p><h3>Generalization</h3><p>When <em>“class B has a generalization relationship with class A”</em> it is <em>“stronger than a composition”</em>, since <em>“class B </em><strong><em>is a</em></strong><em> sub type of class A”</em>. Generalization (also referred as the <strong><em>“IS A”</em></strong> relationship) is the strongest relationship that could exist between 2 classes in a UML class diagram and is related with <em>“inheritance”</em> in Object-Oriented literature.</p><p>Our example in Figure 11 illustrates (<em>“Class A”</em> -&gt; “BaseClass” &amp; <em>“Class B”</em> -&gt; “ChildClass”) on how to map a <em>“generalization”</em> relationship modelled between 2 classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*494aWICO0V9AfoflmtRSYw.png" /><figcaption><strong>Figure 11 — Mapping a “Generalization” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>Unlike other relationships, a change in attributes or methods in the “BaseClass” directly affects the behaviour of the “ChildClass”.</p><h3>Realization</h3><p>When <em>“class B has a realization relationship with interface A”,</em> <em>“class B </em><strong><em>is a</em></strong><em> sub type of the interface type A”</em>. However unlike Generalization, class B needs to adhere to <em>“only the specification”</em> of interface A. <em>“The implementation of class B </em><strong><em>can freely evolve on its own</em></strong><em> as long as it adhere’s the specification of interface type A”</em>.</p><p>Our example in Figure 12 illustrates (<em>“Class B”</em> -&gt; “GatewayServiceImpl” &amp; <em>“Interface A”</em> -&gt; “IGatewayService”) on how to map a <em>“realization”</em> relationship modelled between a class and an interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z2Gx2MKWkOweGd5_6b7lZA.png" /><figcaption><strong>Figure 12 — Mapping a “Realization” from “UML Design” to “Java Implementation”</strong></figcaption></figure><p>In most Object-Oriented programming languages, a class is usually allowed to extend only from one other class; whereas a class is allowed to implement any number of interface types.</p><h3>UML Class Stereotypes</h3><p>Once your UML class diagram has expanded up to 20–50 classes, it is often convenient to classify these classes into several <em>“meaningful categories”</em>. In the <em>“UML class diagram”</em> terminology these <em>“meaningful categories”</em> are called <em>“stereotype”</em>s. Some of the most popular UML class stereotypes (see Figure 13) are;</p><ul><li>Entity — UML classes those represent information those are usually persisted in the system (e.g. OrderConfirmation, Invoice, Payment Request)</li><li>Controller — UML classes those contain control logic mostly related to the business logic of the system (e.g. OrderHandler, PaymentScheduler)</li><li>Boundary — UML classes those interact with end users, integration points of the system (e.g. PaymentRequestUI)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHHYPZ2bxjpmBeaIbjmM_w.png" /><figcaption><strong>Figure 13 — Identifying UML Class “Stereotype”s</strong></figcaption></figure><p>Note that Figure 13 is <em>“</em><strong><em>NOT</em></strong><em> a UML class diagram”</em>, but an illustration drawn to explain the nature of different UML class stereotypes.</p><p>In an actual UML class diagram, stereotypes are indicated in a UML class <em>“above the class name”</em> as illustrated in Figure 14.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhYt1vf7OP65NgdHohYmwQ.png" /><figcaption><strong>Figure 14 — UML class diagram with Class “Stereotype”s</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*NIRfe5CDyVkgkSQYzpYuOw.png" /><figcaption><strong>Figure 15 — 3-Tier Architecture</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*s0jH7Wcg2sM1xIagVYW2FQ.png" /><figcaption><strong>Figure 16 — “Interface” as a “Class Stereotype”</strong></figcaption></figure><p>It is not a rule of thumb, but in practice, most of the classes <em>“stereotype”</em>d as Entity, Controller and Boundary; respectively map with Data, Logic and Presentation Tiers of the conventional 3-tier architecture (see Figure 15).</p><p>Some UML literature use “interface” as a class stereotype in order to identify an interface unambiguously from classes within a UML class diagram (see Figure 16).</p><h3>Conclusion</h3><p>The knowledge behind <em>“mapping a UML class diagram to implementation code”</em> aids programmers at least during 2 of their routine encounters as illustrated in Figure 17.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PAKclkZfQVvpv6m7NVnEqQ.png" /><figcaption><strong>Figure 17 — Using “UML Design” &amp; “Java Code” during Forward &amp; Reverse Engineering</strong></figcaption></figure><ul><li>During <strong><em>“Forward Engineering”</em></strong> — Multiple programmers can work on developing different parts of a newly built software system based on a pre-agreed <em>“UML class diagram”</em></li><li>During <strong><em>“Reverse Engineering”</em></strong> — Upon receiving the implementation code of a software system with lots of <em>“class”</em>es and carrying no design documentation, programmers can work on visualizing the overall design of the software system based on the program code they already have</li></ul><p>Interested in taking that initial step in improving your business by designing and developing a value-driven IT system? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=405f00e22bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lexicon-digital/inside-the-object-oriented-toolbox-mapping-between-design-implementation-405f00e22bd">Inside the Object-Oriented Toolbox— Mapping between Design &amp; Implementation</a> was originally published in <a href="https://medium.com/lexicon-digital">Lexicon Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Blockchain — How it works!]]></title>
            <link>https://medium.com/thecapital/understanding-blockchain-how-it-works-5772e29421b8?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5772e29421b8</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Wed, 13 May 2020 14:00:03 GMT</pubDate>
            <atom:updated>2020-07-12T13:39:42.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Wdgq_v0habT3xDP" /><figcaption>from <a href="https://www.investopedia.com/terms/b/blockchain.asp"><strong>Investopedia</strong></a></figcaption></figure><h3>Understanding Blockchain — How it works!</h3><h4>By <a href="https://medium.com/u/b1da499622a3">Wimal Perera</a> on The Capital</h4><p><strong><em>“Bitcoin”</em></strong> and <strong><em>“Blockchain Technology,”</em></strong> nowadays, are 2 of the most frequently heard words within technical communities; especially amongst those working in banking and finance. However, the lack of foundational concept knowledge behind <strong><em>“blockchain technology,”</em></strong> has made understanding <strong><em>“blockchain”</em></strong> difficult.</p><p>A predecessor article (termed <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><strong><em>“Understanding Blockchain — Foundation”</em></strong></a>) explains several prerequisite concepts helpful for understanding the internals of <em>“blockchain technology,”</em> as listed below.</p><ol><li>Ledger (simplified in-line with the context of understanding blockchain)</li><li>Cryptographic Hash Functions</li><li>Symmetric &amp; Asymmetric Key Cryptography</li><li>Digital Signatures</li><li>De-centralized Network</li></ol><p>The above 5 terms will be interchangeably used throughout this article while explaining <em>“how blockchain works.”</em> Please feel free to look out for them under relevant sections within <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><strong><em>“Understanding Blockchain — Foundation”</em></strong></a><strong><em> </em></strong>article, if you haven’t heard about any of them before or whenever you need more clarity on them while reading this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YFpiDifhn5aPLV3W.png" /><figcaption><strong>Figure 1 — Blockchain Overview</strong></figcaption></figure><p>As per the conclusion from <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><strong><em>“Understanding Blockchain — Foundation;”</em></strong></a><strong><em> “Blockchain”</em></strong> is a set of tools that can be used to implement a <strong><em>“distributed ledger,”</em></strong> that could be <strong><em>“de-centrally verified”</em></strong> and <strong><em>“de-centrally computed” </em></strong>(see Figure 1). So how can we make sure that everyone stays consistent and non-fraudulent within a <strong><em>“de-centrally ledger network?”</em></strong> That is why we need <em>“cryptographic hash functions”</em> and <em>“digital signatures.”</em></p><p>Our story starts from a <strong><em>“centralized ledger”</em></strong> between 4 friends Alice, Bob, Casey, and Daniel (similar to left-hand side of Figure 1. See also Figure 2). So far there are 4 transactions in our <em>“centralized ledger.”</em> Once a transaction happens between 2 people, anyone can write the transaction in the public area for others to know. We can see that Alice, Bob, Casey, and Daniel have $30, $35, $65, and $65 in their accounts as their latest balances upon completion of the final (i.e. 4th) transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wxa_egycoZS47dO-.png" /><figcaption><strong>Figure 2 — A Non-Secure Centralized Ledger</strong></figcaption></figure><p>Although both, the <em>“traditional centralized bank system ledger”</em> and the <em>“distributed blockchain ledger”</em> (that we’re going to read here) have the common goal of providing security; the significance of blockchain is that the ability to make secure transactions even under the absence of a third-party regulatory body (such as the bank).</p><p>In the following sections of this article, let us investigate how we can transform this <em>“un-secure centralized ledger”</em> into a <em>“decentralized secure ledger”</em> that <em>“does NOT depend upon the control of any third party”</em> (such as a bank/regulatory body).</p><h3><strong>Introducing Digital Signatures</strong></h3><p>Let’s focus on simple things first. The ledger in Figure 2 has the problem of validating whether the <em>“payer”</em> of each transaction was actually responsible for;</p><p>a) doing the payment related with a given transaction for the <em>“payee”</em></p><p>b) recording the transaction in the ledger after doing the payment</p><p>For instance considering the transaction <em>“Alice pays Bob $20,”</em> Alice (who is the <em>“payer”</em>) could later say that she didn’t pay $20 for Bob and she wasn’t the one who recorded that transaction in the ledger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wmfcUHti5wlh6UPMl87XiA.png" /><figcaption><strong>Figure 3 — Ledger with Traditional Signatures for Each Transaction</strong></figcaption></figure><p>The immediate solution to fix this problem would be introducing signatures as in Figure 3.</p><p>What if Casey practiced Alice’s signature and forged it to create a new transaction the way Alice did? Also is it possible for Daniel to insert his transaction to the middle of the ledger between Bob’s and Casey’s transaction and be dishonest about it?</p><p>The solution for solving the above problems is;</p><p>a) modify the format of the transaction to -&gt;</p><p><strong><em>{sequence_id} {transaction_contents}</em></strong></p><p>e.g. <em>“01”</em> <em>“Alice pays Bob $20”</em></p><p>b) introduce <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><em>“asymmetric key cryptography”</em></a> into the ledger in which <em>“each person”</em> participating in the ledger must have their <em>“own key pair”</em> (i.e. own public key and private key)</p><p>c) <em>“payer”</em> <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><em>“digitally signs”</em></a> each transaction contents, in which the <em>“hash signed”</em> using payer’s private key is generated based on the <em>“proposed transaction format in a)”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FMLX5df2rohWo2TbrBxXA.png" /><figcaption><strong>Figure 4 — Ledger with Digital Signatures for Each Transaction</strong></figcaption></figure><p>Elaborating more on the solution illustrated in Figure 4, we can see the below characteristics.</p><ol><li>Casey can’t deny the fact that she didn’t do transaction 03 since Casey only knows about her <em>“private key”</em></li><li>Anyone can verify transaction 02’s contents on the ledger with Bob’s <em>“digital signature”</em> and verify that the contents of transaction 02 are not fraudulently modified by someone other than Bob (using Bob’s <em>“public key”</em>)</li><li>The <em>“digital signature”</em> annexed with transaction 01 (i.e. <em>“AliceDS_01”</em>) is different from the <em>“digital signature”</em> annexed with transaction 05 (i.e. <em>“AliceDS_05”</em>), although both signatures belong to Alice. The reason is although Alice uses her same private key in both cases; the contents of the transactions are different. Hence each <em>“unique digital signature”</em> in <em>“each transaction”</em> verifies; not only the identity of the person who signed but also the total content of the transaction being signed.</li></ol><p>Our solution in Figure 4 has the below 2 problems.</p><ol><li>Our ledger is still centralized. Hence we need some common place to store it and it needs to be looked up by some regulatory body (such as a bank). How do we de-centralize our ledger?</li><li>As of figure 4, Alice has the lowest account balance so far. So how do we prevent a situation in which Alice tries to pay $30 for Bob resulting in her overspending?</li></ol><h3><strong>De-Centralizing the Ledger</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AU-p2WX1QNfZKYakfnIf_w.png" /><figcaption><strong>Figure 5 — Each Participant Syncing his/her own copy of the Ledger</strong></figcaption></figure><p>Now we’re one step closer to the world of blockchain; in which our latest solution adheres to the same rules of the ledger described in Figure 4, but each individual will have his/her <em>“own ledger”</em> instead of having a <em>“centralized ledger.”</em> So in this system, when Alice wants to pay $10 to Bob, she will create a transaction with a unique id, include her digital signature (as in Figure 4), and then <em>“broadcast”</em> this information (i.e. digitally signed transaction) to all the participants in the system. How does <em>“each recipient”</em> get to know that the transaction they received via <em>“broadcast”</em> was actually <em>“broadcast”</em>ed by the person described in the transaction? By verifying the <em>“digital signature…”</em></p><p>However, the main problem in this system is how would all participants <em>“synchronize”</em> their own individual ledgers up to the latest transaction that occurred within the system?</p><p>This was the exact problem addressed in the creation of Bitcoin. But just before looking at the solution (i.e. the anatomy of a <em>“blockchain”</em>) we need to look more deeply into an associated concept called <em>“proof of work.”</em></p><h3>Proof of Work</h3><p>A <strong><em>“proof of work”</em></strong> in <em>“blockchain context”</em> is a <em>“valid answer”</em> (usually a string in most cases) for any computational problem having the below characteristics.</p><p>a) <em>“Finding an answer for the problem”</em> shouldn’t be straight forward and should require,</p><ol><li>a <em>“significantly large amount of time” </em>(at least the <em>“average guaranteed time”</em> taken to solve a single such problem has to be significantly large compared to the average time taken to execute a single transaction in the ledger within a given time span such as over a day)<em> </em>and</li><li>a <em>“significant computational effort” </em>(the required effort has to be significantly large enough so that there exists <em>“NO non-genuine shortcuts”</em> and hence persuade anyone willing to try to solve the problem <em>“only by genuine means”</em> and <em>“obtain a reward”</em> upon solving the problem in the <em>“genuine”</em> way)</li></ol><p>b) However <em>“once a valid answer is found for the given problem, verifying that existing answer”</em> could be done by anybody <em>“effortlessly in seconds.”</em></p><p><strong><em>Proof of Work: Concept — A Working Example</em></strong></p><p>Given that we have the below transaction content in our ledger,</p><p><strong><em>{ “06” “Alice pays Bob $10” “AliceDS_06” }</em></strong></p><p>what is the <em>“string”</em> we need to append to the above transaction content so that we can get an MD5 cryptographic hash having 20 zeros in front? (Note that <em>“AliceDS_06”</em> is Alice’s digital signature, which is unique for this 06th transaction)</p><p>In other words, what is the value of <strong><em>“x”</em></strong> in the below expression?</p><p><strong>MD5[ <em>{“06” “Alice pays Bob $10” “AliceDS_06”}</em></strong><em> </em><strong><em>“x”</em></strong><em> </em><strong>]</strong></p><p><strong>=</strong> <strong><em>{20 zeros}{rest of the MD5 hash}</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nn7Beo7z8XtfQvKjEOCLFQ.png" /><figcaption><strong>Figure 6 — Finding a Solution as “Proof of Work”</strong></figcaption></figure><p>When you see the above problem finding the value of <em>“x”</em> is computationally expensive since the only way to do it is to keep on applying different <em>“arbitrary string”</em>s until an <em>“MD5 hash”</em> is found with <em>“20 zeros in front” </em>(see Figure 6 and the properties of a <em>“useful cryptographic hash function”</em> described in <a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0"><strong><em>“Understanding Blockchain — Foundation”</em></strong></a>). As illustrated in Figure 6 (according to the example, our hash function <strong><em>H</em></strong> is <strong><em>MD5</em></strong>), since we need 20 zeros in front, for the average case we would need to attempt 2²⁰ times iteratively with 2²⁰ different <em>“arbitrary string”</em>s to find an <em>“answer” </em>(i.e. one among the 2²⁰ different strings we tried)<em> </em>as a valid <em>“proof of work.”</em></p><p>Hence the <em>“average guaranteed time”</em> taken to solve the above problem is significantly large (of course you could be instantly lucky to end up with the 1st random string you try. But that will be less than 1 out of millionth times!).</p><p>Some of the blockchain literature refers to this <em>“valid answer for x”</em> as <em>“cryptographic nonce”</em> or <em>“nonce.”</em></p><p>However, once a <em>“valid answer for x” </em>(i.e. a <em>“valid nonce”</em>) is known, its verification is straight forward. All we have to do is generate the <em>“MD5 hash”</em> by appending <em>“x” </em>(i.e. the known <em>“valid nonce”</em>)<em> </em>and see if the <em>“generated hash”</em> has 20 zeros in front.</p><h3>Using Proof of Work within a De-Centralized Ledger</h3><p>Different <em>“blockchain”</em>-based (which we will see what in the next section shortly) implementations might enforce the usage of this <em>“proof of work”</em> in different ways. Some systems might perform <em>“a proof of work per every ledger transaction”</em>, some may perform <em>“a proof of work per a batch of transactions”</em> etc. For the simplicity of explanation, I’ll be referring to the scenario of <em>“one proof of work per every single ledger transaction,”</em> which is the most inefficient.</p><p>Also as we discussed in the previous section, solving a <em>“proof of work”</em>-based problem<em> </em>genuinely requires a <em>“significant effort”</em> and this effort needs to be rewarded. This <em>“rewarding upon obtaining a valid nonce for a given proof of work”</em> too is done in different ways in different blockchain implementations. Some systems will reward the problem solver a percentage commission, out of the total amount in the transaction.</p><p>For instance going back to our latest ledger solution in Figure 5, since all transactions are <em>“broadcast”</em>ed anyone can do the <em>“proof of work”</em> for anyone else’s transaction and upon providing a <em>“valid nonce”</em> can get a reward for doing it.</p><p><strong><em>Proof of Work: Rewarding — A Working Example</em></strong></p><p>Imagine that Alice has <em>“broadcasted”</em> (as in Figure 5) a new transaction;</p><p><strong><em>{ “06”</em> <em>“Alice pays Bob $10” “AliceDS_06” }</em></strong></p><p>and that Casey is willing to find a <em>“valid nonce”</em> by doing the <em>“proof of work”</em> for Alice’s transaction (<em>“AliceDS_06”</em> is the digital transaction annexed by Alice for her transaction contents).</p><p>Let’s assume that our hypothetical distributed ledger system has a mutual agreement among all of its users to pay 1% of commission out of the actual transaction amount for the person doing <em>“proof of work.”</em></p><p>First Casey will verify Alice’s transaction by using Alice’s <em>“digital signature.”</em></p><p>Once verified, since Casey needs to collect her reward upon successful completion of <em>“proof of work;”</em></p><ol><li>she will split the original transaction from Alice into 2 split-transactions</li><li>append the split-transactions with the original transaction content</li><li>digitally sign this total transaction content from 2</li></ol><p><strong><em>{</em></strong></p><p><strong><em>{ “06”</em> <em>“Alice pays Bob $10” “AliceDS_06” },</em></strong></p><p><strong><em>{ “Alice pays Bob $9.90”, “Alice pays Casey $0.10” }</em></strong></p><p><strong><em>} “CaseyDS_06”</em></strong></p><p>Then Casey will find a <em>“valid nonce”</em> by doing <em>“proof of work.”</em> Casey will use the <em>“total contents of the original and resulting split transactions” </em>signed with Casey’s digital signature, for her <em>“proof of work”</em> and will end up with a <em>“valid nonce”</em> (such as <em>“345abc12tuv3”</em>) upon successful completion.</p><p>Since the split transaction content has 2 unique <em>“digital signatures”</em> from Alice (which is <em>“AliceDS_06”</em>) and Casey (which is <em>“CaseyDS_06”</em>), it proves that;</p><ol><li>Casey has used the original transaction <em>“broadcasted”</em> by Alice</li><li>The <em>“valid nonce”</em> (i.e <em>“345abc12tuv3”</em>) being discovered upon successful completion of <em>“proof of work”</em>, belongs to Casey</li></ol><p>So ultimately,</p><ol><li>Bob will receive only $9.90 out of $10.</li><li>Alice and Bob will witness $0.10 cents as a <em>“charge made by the system”</em> for the transaction.</li><li>Whereas for Casey $0.10 cents is her reward for appreciating the <em>“significant effort”</em> she made to find a <em>“valid nonce”</em>.</li></ol><p>Once again please note that the above is only a high-level example to understand the concepts in general, whereas the actual implementations of <em>“blockchain-based distributed ledger”</em> systems would vary from one to another.</p><p><strong><em>Bitcoin Mining</em></strong></p><p>In terms of <em>“Bitcoin”</em> (or <em>“Cryptocurrency”</em> in general, which is only a single practical application of <em>“Blockchain”</em>); one’s earnings made by supplying <em>“nonce”</em>s after solving <em>“proof of work”</em>s for transactions done by somebody else is called <strong><em>“Bitcoin Mining.”</em></strong></p><h3>From Distributed Ledger to BlockChain</h3><p>I work for a software company named <a href="https://lexicon.com.au/our-team/">“Lexicon Digital.”</a> Based on all information we’ve discussed so far I’m going to define a data structure which I will call a <strong><em>“</em></strong><em>hypothetical lexicon</em><strong><em> block”</em></strong><em> </em>(see Figure 7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHRzN293zW7vY3wp2VJQmQ.png" /><figcaption><strong>Figure 7 — The Hypothetical “Lexicon Block”</strong></figcaption></figure><p>Note that the keyword <strong><em>“block”</em></strong> is very important. Why I call it the <em>“hypothetical lexicon block”</em> is that different blockchain implementations use slightly different design models for defining the anatomy of their block. We use this <em>“hypothetical lexicon block”</em> for the sole purpose of understanding how blockchain works at a high level.</p><p>As you can see the right hand side of Figure 7 defines the generic data structure of our <strong><em>“lexicon block”</em></strong> and left hand side illustrates an example. My assumptions related to the example on the left, are as below.</p><ol><li>We do a <em>“proof of work per each transaction”</em> in our <em>“lexicon blockchain”</em></li><li>Prior to getting involved in the transaction encapsulated inside <em>“Block 10451”</em>; Alice, Bob and Casey had $20, $20 and $25 in their wallets</li><li>Casey did the <em>“proof of work”</em> for Alice’s transaction</li><li>The reward (i.e. <em>“mining” </em>in terms of <em>“cryptocurrency”</em> world) for <em>“proof of work”</em> in our <em>“Lexicon Blockchain System”</em> is a flat rate of 1% out of the total transaction amount (in this case 1% out of $10 is $0.10)</li><li>The valid answer (i.e. <em>“nonce”</em>) found by Casey after successfully completing the <em>“proof of work”</em>, for the transaction in <em>“Block 10451”</em> is; <em>“35467xyz89abc024”</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWlHf88xd2EkAs9Gos7d6Q.png" /><figcaption><strong>Figure 8 — Formation of the “Lexicon BlockChain” with Multiple “Lexicon Blocks”</strong></figcaption></figure><p>I hope it&#39;s clear to you by now why we call it <em>“blockchain,”</em> it is because each block is associated with its previous block (similar to a LinkedList) and this entire <em>“chain of blocks” </em>together is what we use to reveal all information from the ledger in a given snapshot of time (see Figure 8).</p><p><strong><em>Adjusting the Contents Used for finding a Nonce during Proof of Work</em></strong></p><p>Also, note that the last section of the <em>“block structure definition”</em> (see Figure 7 right) is very important which states <em>“finding a valid nonce for the proof of work using all contents included in the block.”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzZluYNNVthUwjzvq4u6eQ.png" /><figcaption><strong>Figure 9 — “Proof of Work Problem Definition” for the “Lexicon Blockchain”</strong></figcaption></figure><p>Comparing with the <em>“proof of work”</em> example we discussed in the previous section (with regards to <em>“rewards”</em> for <em>“proof of work”</em>); in this <em>“lexicon blockchain” </em>we will additionally add;</p><ol><li>the <em>“current block id”</em> and</li><li>hash derived from the <em>“total contents of the previous block”</em></li></ol><p>when finding a <em>“valid nonce”</em> during doing <em>“proof of work”</em> for each <em>“block” </em>(see Figure 9).</p><p><strong><em>Preventing Overspending</em></strong></p><p>For instance, before Alice doing the transaction of paying $10 to Bob, we can traverse all the way down in the previous blocks, through the <em>“blockchain,”</em> and reach the most recent Alice’s transaction to get her current balance. Hence we can <strong><em>“prevent Alice from overspending”</em></strong> if she doesn’t have at least $10 with her. If Alice has less than $10, no one will do the <em>“proof of work”</em> for Alice. Also even if Alice does the <em>“proof of work”</em> for her transaction, no one will accept a <em>“block”</em> having negative account balances. Also, Alice is unable to update her previous balance fraudulently after doing a transaction and add it as a block to the middle of the blockchain, since the <em>“next block”</em> will have the <em>“hash of the previous block contents,”</em> <em>“next-next block”</em> with <em>“hash of next block contents”</em> and so on.</p><p><strong><em>Distributed Blockchain-based Ledgers</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlADXFGIvCawUY34BmCKEA.png" /><figcaption><strong>Figure 10 — Each User has his/her own copy of the Ledger represented as a “Lexicon Blockchain”</strong></figcaption></figure><p>Everyone in the lexicon network will have their <strong><em>“own copies of lexicon blockchain-based Ledgers” </em></strong>(see Figure 10 versus Figure 5). Having the latest block in your own copy of <em>“blockchain-based ledger”</em> is not required for you to do a new transaction since you know how much actual balance you’ve got in your wallet. But if you try to <em>“overspend,”</em> other’s in the network will get to know your financial status from their own <em>“blockchain-based ledger”</em>s and no one will be willing to do a <em>“proof of work”</em> for your transaction. Thus your transaction won’t be included within the <em>“distributed blockchain.”</em> So I leave it up to you critically think on several edge case scenarios in this regard and see how <em>“blockchain”</em> could come into the rescue.</p><p><strong><em>Bitcoin Wallet Address</em></strong></p><p>One last thing to note is that we used names like Alice, Bob, Casey, etc. to identify individuals in our network. But in the real world, since names might not be unique, most of the blockchain implementations use a globally unique id to identify the wallet of each individual uniquely. In bitcoin context, this is referred to as your <strong><em>“bitcoin wallet address.”</em></strong></p><h3>Preventing/Detecting Fraud in the “Lexicon BlockChain”</h3><p><strong><em>Scenario 1 — Fraud Prevention: Alice is trying to steal money from Bob’s Wallet</em></strong></p><p>Suppose Alice wants to <em>“broadcast”</em> a fraudulent transaction for the system saying;</p><p><strong><em>{ “01 Bob pays Alice $10 BobDS_01” }</em></strong></p><p>to steal from Bob’s wallet; she can’t do it since Bob needs to <em>“digitally sign”</em> his transaction and only Bob has access to his own <em>“private key”</em>.</p><p><strong><em>Scenario 2 — Fraud Detection: Alice is trying to insert a fake block by saying she paid money to Bob which she actually didn’t</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GRp7ao6yq0_JEaJLlxcHQ.png" /><figcaption><strong>Figure 11 — Casey’s Intelligent Copy of “Lexicon Blockchain” with “Candidate Future Blocks Buffer”; identifying Alice’s fraud transaction-based Blocks</strong></figcaption></figure><p>Assume that Alice attempts to deceive the <em>“blockchain,”</em> by appending a <em>“fraud block”</em> with a <em>“fake transaction”</em> which she didn’t actually do (i.e. which she didn’t <em>“broadcast”</em>) by saying <strong><em>“01 Alice pays Bob $10 AliceDS_01”</em></strong> (such as introducing <em>“Block 11351”</em> in Figure 11 at time t = t1).</p><p>In a scenario like this there will be 2 continuations (i.e. a <em>“fork”</em>) in the <em>“future blockchain”</em> (see blocks proceeding from <em>“Block 11351”</em> in Figure 11 at t = t1 and t = t2);</p><ol><li><strong><em>“Fraudulent Blockchain”</em></strong> formed to continue deception in which Alice is doing the <em>“proof of work”</em> for each <em>“block” </em>(shown as <em>“red”</em> in Figure 11)</li><li><strong><em>“Genuine Blockchain”</em></strong> formed with the <em>“collective effort”</em> of all <em>“miners”</em> in the <em>“lexicon network” </em>(shown as <em>“green”</em> in Figure 11)</li></ol><p>Since Alice created her <em>“fraud transaction”</em> <em>“under the hood”</em> without <em>“broadcast”</em>ing she has to;</p><ol><li>do the <em>“proof of work”</em> for the <em>“fraud block”</em> she’s going to create to represent her <em>“fraud transaction”</em> and</li><li>continue with <em>“creating” </em>and <em>“doing</em> <em>proof of work”</em> for all the <em>“next blocks”</em> to represent <em>“all the genuine transactions”</em> happening in the <em>“lexicon blockchain”</em> after her <em>“fraud transaction.” </em>This is because no one else’s <em>“copies of blockchains”</em> are aware of Alice’s fraud transaction. Note that the <em>“proof of work”</em> required to create each block is related to the <em>“hash of the total contents from the previous block.”</em></li></ol><p>But as we learned earlier <em>“proof of work”</em> is <em>“time-consuming”</em> and <em>“effort-consuming,”</em> and this scenario is one of the reasons WHY IT HAS TO BE.</p><p>Because the time and effort required to complete each <em>“proof of work”</em> is <strong><em>“significantly high,”</em></strong> Alice will run out of resources to cope up with the <em>“speed in which the genuine blockchain of the network is getting built”</em> by the <em>“collective effort of all miners”</em> in the network.</p><p>Hence during a <em>“blockchain fork”</em> due to fraud, the real <em>“genuine blockchain”</em> will always end up as the <em>“longest blockchain”</em> after passing a significant amount of time (see time t = t2 in Figure 11).</p><p>According to Figure 11, Casey won’t be able to identify the real versus fake block out of the 2 duplicate <em>“Block 11351”</em>s at time t = t1 (which is why both <em>“Block 11351”</em>s in Figure 11 at time t = t1 are marked in <em>“green”</em>). However as time passes and reaches time t = t2 (in Figure 11), Casey becomes aware that the much <em>“shorter blockchain”</em> having only 2 blocks is the <em>“fraud”</em> one. Hence she marks these <em>“2 red blocks 11351, 11352”</em> in the <em>“shorter blockchain”</em> as <em>“fake blocks” </em>(in <em>“red”</em>) and dumps them from <em>“her own maintained copy of blockchain”</em>. Further, Casey appends the <em>“longer green blockchain from Block 11351 to 11360” </em>(which is the <em>“genuine blockchain”</em>) to <em>“her own copy of blockchain.”</em></p><p>So every time when anyone in the network adds new blocks to their own copy of <em>“lexicon blockchain” </em>they need to follow Casey’s approach (see Figure 11) in which;</p><ol><li>he/she needs to maintain a <em>“buffer”</em> of potential next blocks (i.e. <em>“candidate future blocks”</em>) to be added to his/her <em>“own copy of blockchain”</em> WITHOUT immediately adding new blocks upon receipt from a <em>“miner broadcast”</em> and</li><li>in case of a <em>“blockchain fork”</em> (i.e. there are <em>“multiple potential blockchains”</em> in the <em>“candidate future blocks buffer”</em>) wait for some significant time, find the <em>“fastest-growing longest blockchain”</em> which is the <em>“genuine”</em> one and discard all other <em>“fraudulent blocks”</em> belonging to <em>“fake blockchains”</em>.</li></ol><h3>Conclusion</h3><p>The world-famous <em>“Bitcoin”</em> (in general <em>“cryptocurrency”</em>) is only a single application of <em>“blockchain technology.”</em> I leave it up to you to think about other avenues in which we could use <em>“blockchain;”</em></p><ol><li>How about developing a federal voting system for Australia using <em>“blockchain?”</em> Can it be cheated? The simplest case, presidential election, every voter has $1 which is his vote. He can only spend this $1 to one of the presidential candidates. Can this system be trusted?</li><li>How about using <em>“blockchain”</em> to maintain B2B and B2C transactions happening within a business? All stakeholders in the business can be considered as all parties in its <em>“supply-chain based blockchain network.”</em></li></ol><p>Finally, congratulations! on reaching the end of this article. Having reached this point, you will be in a better position to understand how the internals of blockchain works and their applications. Do think about different edge cases that could happen within a <em>“blockchain</em> <em>network”</em> and critically argue how <em>“blockchain technology itself”</em> would come for the rescue.</p><p>Interested in taking that initial step on transforming your supply chain or banking network by applying blockchain? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><p><a href="https://twitter.com/thecapital_io">JavaScript is not available.</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F3c1144%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F3c1144&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b6b127891c5c8711ad105e61d6cc81f/href">https://medium.com/media/3b6b127891c5c8711ad105e61d6cc81f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5772e29421b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thecapital/understanding-blockchain-how-it-works-5772e29421b8">Understanding Blockchain — How it works!</a> was originally published in <a href="https://medium.com/thecapital">The Capital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Blockchain — Foundation]]></title>
            <link>https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c982f4779ef0</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[hash-function]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[digital-signatures]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 08:23:15 GMT</pubDate>
            <atom:updated>2020-05-24T07:51:05.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OeTi3LKUOLmsAxvV" /><figcaption><strong>from </strong><a href="https://www.investopedia.com/terms/b/blockchain.asp"><strong>Investopedia</strong></a></figcaption></figure><h3>Understanding Blockchain — Foundation</h3><p><strong><em>“Bit Coin”</em></strong> and <strong><em>“Blockchain Technology”</em></strong>, are 2 of the most frequently heard words within technical communities nowadays; especially among the ones attached with banking and finance. However, the lack of in-depth understanding of foundational concepts behind <strong><em>“blockchain technology”</em></strong>, has made understanding <strong><em>“blockchain”</em></strong> difficult.</p><p>This article explains several prerequisite concepts helpful for understanding <em>“how blockchain technology works”</em>.</p><ol><li>Ledger (simplified in-line with the context of understanding blockchain)</li><li>Cryptographic Hash Functions</li><li>Symmetric &amp; Asymmetric Key Cryptography</li><li>Digital Signatures</li><li>De-centralized Network</li></ol><h3>Ledger</h3><p>In the context of financial accounting; the main accounting record of a company or organization is referred as the <strong><em>“ledger”</em></strong>. The ledger will indicate;</p><ol><li>all the <strong><em>“transactions”</em></strong> done by the company up to a certain date</li><li>how did the amounts owing to the company and each stakeholder, change during each transaction</li><li>the remaining amounts owed by the company and its stakeholders, in relation to all business upon completion of the last recorded transaction</li></ol><p>To aid understanding blockchain, let’s go through a simplified example of a ledger formed between 4 friends; Alice, Bob, Casey and Daniel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBaHkjZILZVrGlRMA6sIjg.png" /><figcaption><strong><em>Alice, Bob, Casey and Daniel have $40, $55, $65 and $45 respectively in the initial ledger.</em></strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pHqW2PqM2cO-XGAp9oCng.png" /><figcaption><strong>Alice pays Bob $20. This is the first “transaction” done in this ledger. Upon completion of the transaction the amounts owned by Alice is reduced to $20. Also the amount owned by Bob is increased to $75. The amounts owned by Casey and Daniel remain the same as they are not included in this “transaction”.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*us-2cPQ746MbTa4_-IDDBw.png" /><figcaption><strong>Similarly the “second transaction” happens between Bob and Casey and their respective amounts are updated upon completing the “second transaction”.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePj2YZ1zu3KboqGJpfWTPw.png" /><figcaption><strong>The third transaction is between Casey and Daniel.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJC5M1Mi5uK6R9x527BdMQ.png" /><figcaption><strong>The fourth transaction is between Daniel and Alice. Hence our ledger has recorded a “transaction history” of 4 transactions, since the start. You can find out the current amounts owned by each stakeholder of this ledger from the final result. You can also calculate the amounts owned by each stakeholder before and after each transaction in the “transaction history” (i.e. the “sequential” record of transactions) by going back and forth.</strong></figcaption></figure><h3>Cryptographic Hash Functions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*C-csSKTbYyilY_HJx4MtCA.png" /><figcaption><strong>Figure 1 — Cryptographic Hash Function</strong></figcaption></figure><p>A cryptographic hash function is a special computer algorithm, which takes a text input of any length and returns a random output text (also called the <strong><em>“hash” </em></strong>or<strong><em> “message digest”</em></strong>) of constant length. Note that for a <em>“given specific input text”</em>, the function must always return the <em>“same hash”</em> every time you run it. (e.g. Figure 2 — for the input string “Hi”, our hash function must always return the given output <em>“hash”</em>, every time when we run our hash function with input “Hi”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1VE5E24AH6_t-qfYXueRQ.png" /><figcaption><strong>Figure 2 — Sample Inputs &amp; Outputs related with a Cryptographic Hash Function</strong></figcaption></figure><p>Also note that the length (i.e. number of characters) of the output string (i.e. <strong><em>“hash”</em></strong>) is always constant irrespective of the length of the input string (see Figure 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6v2vpl_NgoNbUpfkLcjhWA.png" /><figcaption><strong>Figure 3 — Sample Inputs &amp; Outputs related with a Cryptographic Hash Function</strong></figcaption></figure><p>A cryptographic hash function must satisfy several characteristics in order to be <strong><em>“useful”</em></strong>.</p><ol><li>It must be mathematically impossible (or at least computationally extremely expensive) to obtain the original input text by using the output <em>“hash” </em>(see Figure 2 and Figure 3 — it has to be impossible to obtain the <em>“input”</em> texts by using their corresponding <em>“hash”</em>es).</li><li>The generated <em>“hash”</em> (or <em>“digest”</em>) must be significantly different even between 2 different inputs those are minimally different (in Figure 3, observe the significant difference between the output <em>“hash”</em>es even during a slight change of the corresponding <em>“input”</em> text)</li><li>It has to be <em>“computationally infeasible”</em> to generate a <em>“desired arbitrary hash”</em> by using <em>“different modified input texts”</em>.</li></ol><p>One important characteristic that cannot be avoided from a cryptographic hash function is the presence of collisions. The reason for this is that the hash function has to return a fixed length <em>“digest”</em> for any given input text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*5R4AVWBjC-LcavECU9N71Q.png" /><figcaption><strong>Figure 4 — Hash Function and Collision</strong></figcaption></figure><p>Figure 4, illustrates how collisions occur by using a simplified hash function that returns only 16 different hashes. Of course, by careful analysis it could be determined that a simplified hash function as in Figure 4, won’t be able to satisfy all the 3 characteristics of a <em>“useful”</em> hash function. Why? For instance, since we have only 16 different possible “hash”es; it will be easier to find out a modified input text that provides a desired hash, violating 3rd characteristic of a <em>“useful”</em> hash function.</p><p>Hence decreasing the probability for occurring a collision helps making a hash function <em>“useful”</em>. So how can we make a hash function generate a large set of different <em>“hash”</em>es (leading to lesser collisions)? We can do 2 things.</p><ol><li>Increase the size of the character set used to generate the output <em>“hash”</em></li><li>Increase the length (number of characters) of the generated <em>“hash”</em></li></ol><p>For instance if we use an alpha-numeric character set (a-zA-Z0–9) and generate <em>“hash”</em>es of length 10; then our hash function is able to generate 62¹⁰ different <em>“hash”</em>es, leading to less collisions (62 = 26 capitals + 26 simples + 10 numeric digits).</p><p>Do we have real implementations of <em>“useful cryptographic hash functions”</em> as described in this section? <strong>MD5</strong> and <strong>SHA-1</strong> are 2 of the well-known and widely used <em>“useful”</em> cryptographic hash functions.</p><h3>Symmetric &amp; Asymmetric Key Cryptography</h3><p>Cryptography describes different ways on how to exchange secret messages between 2 or more parties, so that any non-related party in the middle is unable to know/understand the actual content of the secret message, although they can access the message. In order to achieve this objective the message sender will <strong><em>“encrypt”</em></strong> the plain readable secret message (i.e. <strong><em>“plaintext”</em></strong>) to an unreadable message (i.e. <strong><em>“ciphertext”</em></strong>) using a <strong>unique</strong> <strong><em>“encryption key”</em></strong> and a <strong>publicly known</strong> <strong><em>“encryption algorithm”</em></strong>. The message receiver will convert (i.e. <strong><em>“decrypt”</em></strong>) the received unreadable <strong><em>“ciphertext”</em></strong> back to original readable message using a corresponding <strong>unique</strong> <strong><em>“decryption key”</em></strong> (not necessarily equal to the unique <em>“encryption key”</em>) and a publicly known <strong><em>“decryption algorithm”</em></strong>. (see Figure 5)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KJTtdh9n31O_2gl0klDI9g.png" /><figcaption><strong>Figure 5 — Encryption and Decryption</strong></figcaption></figure><p>Note that although any non-related party (other than the sender and receiver) can access the <em>“ciphertext”</em> as well as the <em>“encryption/decryption algorithms”</em>, they are still unable to <em>“decrypt”</em> the <em>“ciphertext” </em>and view the actual message <em>“plaintext”</em> content; since they don’t know the full information related to unique encryption/decryption <em>“key”</em>s exchanged between the sender and the receiver.</p><p>Cryptography has 2 broad domains depending on how this encryption and decryption <em>“key”</em>s are exchanged between the sender and the receiver.</p><ol><li>Symmetric Key Cryptography</li><li>Asymmetric Key Cryptography</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyyvlVMW_bpmy3IgfjJEGQ.png" /><figcaption><strong>Figure 6 — Symmetric Key Cryptography</strong></figcaption></figure><p>In symmetric key cryptography, the <em>“encryption key”</em> and <em>“decryption key”</em> exchanged between the sender and receiver are the <strong>SAME</strong>. (see Figure 6) Hence, both parties (i.e. the sender and receiver) need to have an agreement before the secret message communication, for a common key used during encryption and decryption. Examples of well-known and widely used symmetric key encryption algorithm implementations are <strong>DES</strong> and <strong>AES</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*H1N9sI5DQ5hINcUSz_UL2Q.png" /><figcaption><strong>Figure 7 — Symmetric Key Distribution Problem</strong></figcaption></figure><p>Although symmetric key cryptography algorithms are computationally less expensive comparing to asymmetric key algorithms; their main problem is managing the distribution of secret keys (since the sender and receiver has to exchange a common secret <em>“key”</em> prior to their secret communication). As you can see in Figure 7, for establishing 3 different private message channels between 3 people (i.e. 3 parties) we need 3 different symmetric encryption <em>“key”</em>s. For 4 people it is increased to 6 different keys, for 6 people 15 different keys and for n people (n / 2) * (n — 1) different keys.</p><p>In asymmetric key cryptography, <strong>for each party</strong> involved in communicating secret messages; we generate 2 keys (also called a <strong><em>“key pair”</em></strong>) to be used for encryption and decryption of data. This <em>“key pair”</em> has the below characteristics.</p><ol><li>If you encrypt a plaintext message using any of the keys, it could be decrypted ONLY by using the other key.</li><li>If you know one of the keys of a <em>“key pair”</em>, you still cannot derive (or at least it is computationally infeasible to derive) the other key based on the key you have (or by any other means such as using pairs of sample <em>“plaintext”</em> and <em>“ciphertext”</em>)</li></ol><p>Once an asymmetric <em>“key pair” </em>is generated, one of the 2 keys are kept in private with the generated party (called the <em>“private key”</em>) and the other key is published, so that it is known by everyone (called the <em>“public key”</em>). Examples of well-known and widely used asymmetric key encryption algorithm implementations are <strong>RSA</strong> and <strong>Elliptic Curve</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qq91Hd1wm5HksylJLBNJCA.png" /><figcaption><strong>Figure 8— Public Key and Private Key</strong></figcaption></figure><p>Figure 8 illustrates, 2 scenarios about using private key and public key during encryption and decryption.</p><ol><li><strong>Encrypt plaintext with private key and decrypt back with public key</strong> — Refer to Figure 9, where Alice and Bob are 2 people having their own <em>“key pair”</em>s. Alice’s and Bob’s <em>“public key”</em>s are known by everyone (i.e. Alice, Bob and Eve). But Alice’s <em>“private key”</em> is only known to Alice. Bob’s <em>“private key”</em> is only known to Bob. If Alice encrypts any plaintext with her <em>“private key”</em>, both Bob and Eve can decrypt it using Alice’s <em>“public key”.</em> If properly decrypted they (Bob and Eve) become certain that this plaintext was sent by Alice, since Alice is the only person who knows about her <em>“private key”</em>.</li><li><strong>Encrypt plaintext with public key and decrypt back with private key</strong> — Referring back to Figure 9, if Alice wants to send a confidential message to Bob (without it being seen by Eve) she can encrypt the message with Bob’s <em>“public key”</em>. Since the message can be only decrypted with Bob’s <em>“private key”</em> and only Bob has it, Bob will be the only person who is able to decrypt the message. But the issue here is that Bob is not sure whether the message was actually sent by Alice, since Eve can send a fake message imitating Alice, as Eve too knows about Bob’s <em>“public key”</em>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xp7OvbgHTRfXldhGYtsC_Q.png" /><figcaption><strong>Figure 9— Public Key and Private Key, Usage</strong></figcaption></figure><p>We can do a double encryption-decryption to prevent problems in both scenarios (see Figure 10).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RXz8QNsZHi2S5L71-PV4Q.png" /><figcaption><strong>Figure 10— Double Encryption/Decryption</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*ria9Fdgd5-OXtA5obcOqNQ.png" /><figcaption><strong>Figure 11 — How HTTPS Works</strong></figcaption></figure><p>In Figure 9, if Alice is the sender and Bob is the receiver; Alice can encrypt her message (i.e. <em>“plaintext”</em>) from her <em>“private key”</em>, then encrypt the resulting <em>“ciphertext”</em> from Bob’s <em>“public key”</em>. On the receiving end Bob can decrypt the received <em>“ciphertext”</em> with his <em>“private key”</em>, followed by decrypting the result further with Alice’s <em>“public key”</em>. In this case Eve will be unable to view the message as well as wouldn’t be able to send a fake message imitating Alice. Why? Because, Eve neither knows Alice’s <em>“private key”</em> nor Bob’s <em>“private key”</em>.</p><p>Doing a double-encryption all the time reduces performance as asymmetric encryption/ decryption is a computationally intensive operation. Hence most of the secure communication implementations nowadays, initially exchange a <em>“temporary session-based common secret key”</em> for a single communication <em>“session”</em> with asymmetric key encryption. Then this initial temporary session-based common encryption key is used for rest of the communication during the session with symmetric encryption.</p><p>Figure 11 illustrates the workflow followed during initiating an HTTPS client session by a web browser. Note that initially, a <em>“temporary session-based symmetric encryption key”</em> is exchanged by using asymmetric encryption algorithms. Then the less computational symmetric encryption takes place with the temporary symmetric session key.</p><h3>Digital Signatures</h3><p>We all have signed documents with pen and paper. But how many times have we felt that;</p><ol><li>Our signatures can be forged by someone else?</li><li>Or our original signatures can be annexed with different content rather than what we actually signed?</li></ol><p>A <strong><em>“digital signature”</em></strong> is constructed based on cryptographic hash functions and asymmetric key cryptography, providing permanent solutions to both of the above problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DRLfdFftzD_-pgimHNTnlA.png" /><figcaption><strong>Figure 12 — Digital Signatures; Signing and Verification</strong></figcaption></figure><p>Going back to the Alice and Bob scenario (see Figure 9), if Alice wants to sign a document and send to Bob;</p><ol><li>First, Alice will have to create a <em>“cryptographic hash”</em> (e.g. MD5) based on all content of the document (i.e. <em>“plaintext”</em>) she wishes to sign.</li><li>Alice will encrypt the <em>“hash”</em> from step 1 with her <em>“private key”</em>. This is what we call the <em>“digital signature”</em>.</li><li>Alice will attach this <em>“digital signature”</em> to the original document (which we call <em>“digitally signed data”</em>) and send it to Bob over the network.</li></ol><p>At the receiving end Bob will do the verification (see also Figure 12 and Figure 9).</p><ol><li>First, Bob will re-generate a <em>“cryptographic hash”</em> based on content of Alice’s document. Note that Alice and Bob must use the same cryptographic hash algorithm implementation (e.g. MD5).</li><li>Bob will decrypt the received <em>“digital signature”</em> using Alice’s <em>“public key”</em>.</li><li>Bob will compare the <em>“decrypted hash”</em> from Step 2, with the <em>“hash”</em> generated in Step 1.</li></ol><p>If both <em>“hash”</em>es are equal in Step 3, then Bob is certain that (see also Figure 12 and Figure 9);</p><ol><li>The document was originally signed by Alice (since Bob decrypted the digital signature with Alice’s <em>“public key”</em> and only Alice knows about her <em>“private key”</em>)</li><li>Neither Alice nor any intruder in the network (like Eve) altered the document by any means after signing it, since the <em>“hash”</em> generated by Bob got tallied with the <em>“hash”</em> decrypted from the <em>“digital signature”</em>.</li></ol><h3>De-centralized Network</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qedrSgNoU6OY7AluifQjyQ.png" /><figcaption><strong>Figure 13 — Centralized Vs De-centralized Network</strong></figcaption></figure><p>Figure 13, compares and contrasts a centralized and a de-centralized network.</p><p>An example of a <strong><em>“centralized network”</em></strong> is your online banking website. Your bank <strong><em>“dictates the truth”</em></strong>, and only expose related information to you, as the customer. All customers assume what their bank says is true made upon the longterm trust of the banking brand. <strong><em>“Priveleged users”</em></strong> such as your bank manager has the authority to view all transactions (i.e. <strong><em>“centralized bank ledger”</em></strong>) happening in the bank, dictate your interest rates &amp; credit card fees etc.</p><p>An example of a <strong><em>“de-centralized network”</em></strong> is social media (e.g. Facebook, Instagram). Posts initiated by social media consumers are <strong><em>“not dictated”</em></strong> by any <strong><em>“core authority”</em></strong>. Every social media consumer (i.e. <strong><em>“every participant”</em></strong>) can access all posts submitted by him/her and all other participants (i.e. a <strong><em>“distributed ledger of social media posts”</em></strong>). So if there are 2 contradicting posts getting published and shared within the social media network how do you find out which one is true? Well, by looking at the responses to each post and picking up the post appreciated by the majority (i.e. the argument accepted by more than 50%).</p><h3>Putting It All Together</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8eeyME0daVtc4UQodqnbHg.png" /><figcaption><strong>Figure 14 — A preamble to Blockchain</strong></figcaption></figure><p>Figure 14, provides a preamble to <strong><em>“blockchain technology”</em></strong>, for the ones who are curious about it. <strong><em>“Blockchain”</em></strong> is a set of tools that can be used to implement a <strong><em>“distributed ledger”</em></strong>, that could be <strong><em>“de-centrally verified”</em></strong> and <strong><em>“de-centrally computed”</em></strong>. So how can we make sure that everyone stays consistent and non-fraudulent within a <strong><em>“de-centrally ledgered network”</em></strong>? That is why we need <em>“cryptographic hash function”</em>s and <em>“digital signature”</em>s.</p><p>Finally, congratulations! on completing all pre-requisites required to understand the <em>“blockchain technology”</em>. Having reached this point, you will be in a better position to understand <a href="https://medium.com/the-capital/understanding-blockchain-how-it-works-5772e29421b8">how the internals of blockchain works and its applications</a>.</p><p>Interested in taking that initial step on transforming your supply chain or banking network by applying blockchain? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c982f4779ef0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lexicon-digital/understanding-blockchain-foundation-c982f4779ef0">Understanding Blockchain — Foundation</a> was originally published in <a href="https://medium.com/lexicon-digital">Lexicon Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[‘Golden Ratio’ and ‘Fibonacci Numbers’: The Ultimate Toolkit for Defining the Geometry of Universe]]></title>
            <link>https://wimal-perera.medium.com/golden-ratio-and-fibonacci-numbers-the-ultimate-toolkit-for-defining-the-geometry-of-universe-50829526e154?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/50829526e154</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[nature]]></category>
            <category><![CDATA[golden-ratio]]></category>
            <category><![CDATA[fibonacci-series]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Sat, 07 Mar 2020 10:06:28 GMT</pubDate>
            <atom:updated>2020-07-16T06:05:44.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qfMknC-C7AHftRVR.jpg" /></figure><p>The study of mathematical constructs and their implications on Nature helps us to apply that knowledge during designing and engineering man-made structures (such as buildings, robots, machines, websites etc). This makes our engineering more Naturalistic and robust to the changes of the surrounding environment.</p><p>This article is going to describe about a single numerical constant that governs the shape and form of most of the known entities in Nature and the entire universe. In other words, what if I tell you that the structure of all natural shapes and forms of this universe is based on a single number? Believe it or Not, it is true and this article is going to describe this <em>“golden number”</em>, which is called the <strong><em>“golden ratio”</em></strong> and its amazing mathematical implications behind formation of shapes and forms in the universe.</p><p>As the first part of this article, let’s review the definition of <em>“golden ratio”</em> and various geometrical shapes formed based on the value of <em>“golden ratio”</em>.</p><h3><strong>Golden Ratio &amp; Fibonacci Numbers</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/0*XmuU7WeJNXIO9Pw8.png" /><figcaption><strong>Figure 1 — Golden Ratio Definition</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*lv7i61jJSB-X1xI2.png" /><figcaption><strong>Figure 2 — Golden Ratio Derivation</strong></figcaption></figure><p>Suppose we divide any single line into 2 non-equal parts, and the <strong>ratio of lengths</strong> between the longer and shorter part is <strong><em>x:1</em></strong>, the <strong>golden ratio</strong> (denoted by greek letter <strong>φ</strong>)is defined as the value of <strong><em>x</em></strong> in which the <strong><em>longer part length divided by shorter part length </em></strong>(a/b in Figure 1) is also <strong>equal</strong> to <strong><em>the total line length divided by longer part length </em></strong>([a+b]/a in Figure 1).</p><p>The value of the <strong>golden ratio</strong> (<strong>φ</strong>) is a constant which is approximately equal to <strong>1.618</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RLvS91mFwXx0hr3y.png" /><figcaption><strong>Figure 3 — Deriving Fibonacci Numbers</strong></figcaption></figure><p><strong><em>“Fibonacci numbers”</em></strong> is a self-generating series in which; the first two numbers are 1, 1 and each number after that is the sum of the previous two numbers. As you can see in Figure 3, 1+1=2, 2+1=3, 3+2=5, 5+3=8, 8+5=13, 13+8 = 21 and so on…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*1qg-K5S5VehQdjLr.png" /><figcaption><strong>Figure 4 — Fibonacci Numbers and Golden Ratio</strong></figcaption></figure><p>But is there a connection between the “Fibonacci numbers” and the “golden ratio”? As in Figure 4; when you divide any number in the Fibonacci series with the previous number (except during the first few cases), the answer coincides with the value of the golden ratio. (e.g. 34/21, 21/13, 13/8 and so on…)</p><h3><strong>Golden Angle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*oTAhtrFvX8pLuk7m" /><figcaption><strong>Figure 5 — Golden Angle</strong></figcaption></figure><p>Another interesting concept derived from golden ratio is the <strong>“golden angle”</strong>, which is the value of the angle formed when a circle is divided into 2 arcs in which the arch lengths are split as per <em>“golden ratio”</em>, <strong>φ</strong> (see Figure 5). Hence the value of the <em>“golden angle”</em> can be expressed either as an obtuse angle of 137.5 degrees approximately (or as a reflexive angle of [360–137.5] degrees).</p><h3><strong>Golden Spiral</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/0*W8PfNPRuyPPN6OcD.gif" /><figcaption><strong>Figure 6 — Golden Spiral: Formation</strong></figcaption></figure><p>Figure 6 illustrates an animation of a Nautilus shell. The proportion between the blue and white areas observed when traversing the spiral is aligned with 1:1.618 (1:φ), all the time (which is the definition for the <strong><em>“golden spiral”</em></strong>).</p><p>A golden spiral can be constructed using a set of shapes formed with proportions based on <strong><em>“Fibonacci numbers” </em></strong>(Figure 7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*liiipE_ZfO1TrpfN.jpg" /><figcaption><strong>Figure 7 — Golden Spiral: Construction</strong></figcaption></figure><h3><strong>Golden Triangles and Golden Pentagon</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*i_VbfzbKHM6FfvAR.jpeg" /><figcaption><strong>Figure 8 — Golden Acute Triangle (on left) and Golden Obtuse Triangle (on right)</strong></figcaption></figure><p>Figure 8, shows triangles constructed based on the golden ratio, in which 2 to 1 sides having a ratio <strong>φ:1 </strong>between side lengths. The triangle on the left (Figure 8) is called the <strong><em>“golden acute triangle”</em></strong><em> </em>(since all 3 angles are less than 90 degrees).<em> </em>The triangle on the right (Figure 8) is called the <strong><em>“golden obtuse triangle”</em></strong><em> </em>(since one of the angles is greater than 90 degrees).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/0*qgbnznwhs9ANTH1C.png" /><figcaption><strong>Figure 9 — Golden Pentagon</strong></figcaption></figure><p>A regular pentagon (Figure 9), also called the <strong><em>“golden pentagon” </em></strong>is formed by combining <strong>2 golden obtuse triangles and 1 golden acute triangle</strong>.</p><p>Now that we know on how to form various geometrical shapes based on the value of “golden ratio”, the next step of this article will discuss about the amazing correlation of above shapes with natural constructions of the universe.</p><h3><strong>Golden Ratio and Plants</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRaoaAEpimP4cvD691vkBA.png" /><figcaption><strong>Figure 10 — Tree Branch Division versus Fibonacci Numbers</strong></figcaption></figure><p><em>“Golden ratio”</em> is observed in tree branching. As you can see in Figure 10, when a tree trunk grows wide while splitting into branches; the branches tend to split in a pattern that the total branch count at a given height level with the immediate below/above level falls for a ratio between immediate <em>“Fibonacci numbers”</em> (which we know is the value of <em>“golden ratio”</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*j2FoKne54CQY93H8RhbVgg.jpeg" /><figcaption><strong>Figure 11 — Same Orientation of Leaves at Fibonacci Indices</strong></figcaption></figure><p>Usually the nearby leaves in a tree branch are oriented at different directions. In this way when we count the number of leaves along a spiral until finding a leaf with the same orientation in which we started counting (see Figure 11), the number of leaves counted along the spiral tends to align with a <em>“Fibonacci number”</em>. As shown in Figure 11, the number of leaves associated for this characteristic differs from tree species to species, but always fall for a number in the <em>“Fibonacci Series”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/0*gDP0dDlooEJCROpo.gif" /><figcaption><strong>Figure 12 — Tree Leaves and Golden Angle</strong></figcaption></figure><p>If we number the leaves of a tree branch from top to bottom (see Figure 12); the angle in which leaves of any 2 consecutive indices align (e.g. the angular difference between leaf 3 &amp; leaf 4, or leaf 8 &amp; leaf 9 etc), approximates to value of the <em>“golden angle”</em>(approximately 137.5 degrees).</p><p>Trees follow the above patterns related with <em>“golden ratio”</em> during growth, in order to make sure that their leaves absorb the maximum amount of sunlight to enable optimal photosynthesis. These <em>“golden ratio”</em> oriented growth patterns were first observed by Charles Bonnet, a Swiss naturalist during 1754 and was termed as <a href="https://goldenratiomyth.weebly.com/phyllotaxis-the-fibonacci-sequence-in-nature.html"><strong><em>Phyllotaxis</em></strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*l_ihC94WJ1BGI83Z.jpg" /><figcaption><strong>Figure 13 — Formation of Seeds in A Sunflower</strong></figcaption></figure><p>So it propagates all the way to flowers starting from branches and leaves. Figure 13, illustrates how the seeds are formed in the middle of a sunflower (on the right), aligned with a <em>“group of concentric golden spirals”</em> (on the left).</p><p>Figure 14, shows how the formation of flower petals (in this case roses) is based on the multiple <em>“golden spiral”</em> setup, similar to seed formation pattern in Figure 13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*1FyRNd73fgkAm-a4.jpg" /><figcaption><strong>Figure 14 — Rose and its Petals</strong></figcaption></figure><h3>Golden Ratio and Space</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*hhsrdXRU__w5TX6o.jpg" /><figcaption><strong>Figure 15 — Milky Way</strong></figcaption></figure><p>Some of the galaxies in universe (such as Milky Way, Andromeda) are of spiral shape. Their photographs show the resemblance of the <em>“golden spiral”</em> as the basic shape of construction (see Figure 15).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*OgEO5Ure2HZT7D1K.gif" /><figcaption><strong>Figure 16 — Saturn</strong></figcaption></figure><p>Planet Saturn in the Solar System, has proportions related to <em>“golden ratio”</em> among its diameter and rings as illustrated by Figure 16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*-rW0eH7WbhkNeAXU.jpg" /><figcaption><strong>Figure 17 — Planet Years</strong></figcaption></figure><p>The orbital years of planets; Mercury, Venus, Jupiter &amp; Saturn relative to an Earth year approximates to different powers of <em>“golden ratio” (φ)</em> as shown in Figure 17. Hence all the 5 planets together including Earth are called the <em>“golden planets”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*eruehomtftzAFqSR.jpg" /><figcaption><strong>Figure 18 — Shape of the Universe as a Dodecahedron</strong></figcaption></figure><p>A team of scientists and mathematicians have calculated the <a href="https://www.goldennumber.net/universe/">overall shape of the universe</a> based on microwaves received as cosmic background radiation dating back to the infancy of the universe. The answer they’ve come for the shape is a <strong><em>“Dodecahedron”</em></strong>; a 3D shape formed based on the <em>“golden pentagon” </em>(Figure 18).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*JChvayk7at_3Z8nk.jpg" /><figcaption><strong>Figure 19 — The Dodecahedral Space Model</strong></figcaption></figure><p>Figure 19, illustrates on how the space in the universe would fit into a <em>“3D Dodecahedral model”</em>. Although this is still a theory, it can be proved based on cosmic background radiation collected via microwave space antennas.</p><h3>Golden Ratio and Geography</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*WfoitdLwY4uXbJAT.jpg" /><figcaption><strong>Figure 20 — Formation of a Hurricane</strong></figcaption></figure><p>Hurricanes get formed as spirals and tend to align with the <em>“golden spiral” </em>upon formation (Figure 20).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a0OLv5HWuvMR1WFv.jpg" /><figcaption><strong>Figure 21 — Wave Formation</strong></figcaption></figure><p>Wave formation happens similar to hurricanes, in which the wave is slowly shaped towards a <em>“golden spiral”</em> upon its peak (Figure 21).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/0*ZuqcJ1P_iv-b2Ov_" /><figcaption><strong>Figure 22 — Africa</strong></figcaption></figure><p>The African continent is naturally shaped as a <em>“golden spiral” </em>(Figure 22).</p><h3>Golden Ratio and Life</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/0*NuBv2SOt4HbnrdY6.jpg" /><figcaption><strong>Figure 23 — Fetus</strong></figcaption></figure><p>When an embryo develops inside a mother’s womb the overall shape tends to align with the <em>“golden spiral” </em>(Figure 23).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/0*-EcCGL4O-WzjgeNf" /><figcaption><strong>Figure 24 — Golden Ratio and Egg</strong></figcaption></figure><p>Figure 24 illustrates the relationship between a hen egg and the <em>“golden spiral” </em>shape(on the left).</p><p>Also certain proportions of the <em>“egg shape”</em> are closely associated with the <em>“golden ratio”</em> value as illustrated in Figure 24 (on the right).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/0*gicMksc6nILsk8eM.gif" /><figcaption><strong>Figure 25 — Koala Face and Golden Rectangles</strong></figcaption></figure><p>How many <strong><em>“golden rectangles”</em></strong> (rectangles with length:width ratio being φ:1) can you figure out when looking at a Koala’s face? (Figure 25)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*rSdgkDWg-5h-nLIQ.jpg" /><figcaption><strong>Figure 26 — Shape Analysis for a Butterfly</strong></figcaption></figure><p>Figure 26 shows a detailed analysis of a butterfly in relation to its overall shape. The interesting observation to note here is the contribution of fundamental <em>“golden ratio”</em> based shapes; <em>“golden rectangle”</em> and <em>“golden spiral”</em>, for the construction of the overall butterfly shape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQnEeCHuqHre6LMTeD0QlQ.png" /><figcaption><strong>Figure 27 — Snail Shells</strong></figcaption></figure><p>Figure 27 is a collection of photographs containing different snail types. How many <em>“golden spirals”</em> can you find in each snail shell?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*RGUxrRnSkBOrWgD9.jpg" /><figcaption><strong>Figure 28 — Anatomy of an Insect</strong></figcaption></figure><p>The proportions of lengths between head, thorax and abdomen of an insect approximately aligns with different powers of <em>“golden ratio”</em> (see Figure 28).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*y7hOan8rr2vyt484.jpg" /><figcaption><strong>Figure 29 — Beetles</strong></figcaption></figure><p>Figure 29, illustrates the length and width of different types beetles and how these dimensions correspond to <em>“golden ratio”</em> (<em>φ</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*o7hN7FvWBJEFc1Si.jpg" /><figcaption><strong>Figure 30 — Fly Approaching an Object</strong></figcaption></figure><p>When a fly approaches an object it follows a “spiral” path quite close to a <em>“golden spiral”</em> due to the structure of its eyes and the nervous system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*cua26urZ9aeBTgXv.gif" /><figcaption><strong>Figure 31 — Ancestry Code of a Bee and Fibonacci Numbers</strong></figcaption></figure><p>In any bee colony (i.e. a bee hive), there is one big female bee called the “queen” who lays eggs. If the eggs laid by the queen are fertilized by a male bee, then it leads to forming another female bee who would form a new colony as its queen with a subset of male bees in the existing colony. An egg laid by the queen, those are not fertilized by a male bee; forms a male worker bee. Hence every female bee will have both a male and a female parent, whereas every male bee will only have a female parent (see Figure 31). Hence for a particular bee’s ancestry, it will always have a <em>“fibonacci number”</em> of ancestors for a particular earlier generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/0*RFUIm0ClQCvv_Xwr" /><figcaption><strong>Figure 32 — Wing of an Eagle</strong></figcaption></figure><p>Observing birds, we could see that the sub skeleton parts making a complete wing approximates to <em>“golden ratio”</em> between their lengths (see Figure 32).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/0*qdTZuHKg1MQK3aNM" /><figcaption><strong>Figure 33 — Green Falcon</strong></figcaption></figure><p>The overall shape of the head and beak together forms a “golden spiral” in many bird species (Figure 33).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ukr-ssKaL_4GGIDX.png" /><figcaption><strong>Figure 34 — Golden Ratio in Cat Style</strong></figcaption></figure><p>As a final refresher to this section, just think about your Cat looking very cute when lying on the floor confirming the shape of a <em>“golden spiral”</em>.</p><h3>Golden Ratio and Human Body</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*JwmHkzbk_o7JVXb1" /><figcaption><strong>Figure 35 — Human Arm</strong></figcaption></figure><p>Figure 35, illustrates the organization of different proportions in a human arm and their relationship with the <em>“golden ratio”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*XxteX56rkI-DHksH.jpg" /><figcaption><strong>Figure 36 — Proportions of Human Face and Hand</strong></figcaption></figure><p>How many <em>“golden ratio”</em> values can you make by dividing different proportions marked in the hand and face illustrated in Figure 36?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*c3v4i294fjZaU5zM.jpg" /><figcaption><strong>Figure 37 — Golden Ratio and Human Body</strong></figcaption></figure><p>Figure 37; a detailed analysis of <em>“golden ratio”</em> done for a model’s photo, illustrates how <em>“golden ratio”</em> accounts for forming the overall shape of the human body. Here comes a question for all girls, who have read up to this point. How would you decide the height of your shoe heels?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/0*7JcaoJuBtSTXy36v.jpg" /><figcaption><strong>Figure 38 — Human Ear</strong></figcaption></figure><p>Figure 38, shows the contribution of the “golden spiral” when forming the overall shape of the human ear and even its little details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/0*ZbywkinKiqGwJtv3.gif" /><figcaption><strong>Figure 39 — Human Eye</strong></figcaption></figure><p>Figure 39, explains the contribution of <em>“fibonacci circles”</em> for different aspects of the human eye.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wqtJ4CpPSIX0u_gr.jpg" /><figcaption><strong>Figure 40 — Golden Spiral and Curves of the Human Body</strong></figcaption></figure><p>Figure 40, illustrates how you could explain different curvatures of the human body based on the <em>“golden spiral”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/135/0*7lw6kVkTWSB5LoDI.gif" /><figcaption><strong>Figure 41 — Human Foot</strong></figcaption></figure><p>How many <em>“golden ratios”</em> can you make by dividing different lengths measured in your feet? (see Figure 41)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*O1tOuiKEg1yuGZ9U.jpg" /><figcaption><strong>Figure 42 — Golden Ratio and BMI</strong></figcaption></figure><p>Figure 42, illustrates the amazing involvement in <em>“golden spiral”</em> for defining a well-shaped body confirming with a healthy body mass index.</p><p>I hope these evidence prompt you to think that the beauty of a human face could be analyzed by using the <em>“golden ratio”</em>. In fact, it is possible and already done which is a topic for another day. Yet, the interested can read it <a href="https://medium.com/@wimal.perera/finding-my-dream-girl-with-golden-ratio-31a95c7bf219">here</a>.</p><h3>Putting It All Together</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/0*1YGLiAwt7r5Z5DLN.jpg" /><figcaption><strong>Figure 43 — Application of Golden Ratio in Historic Art</strong></figcaption></figure><p>After a comprehensive study about the contribution of <em>“golden ratio”</em> for forming shapes in Nature and universe; this final section focuses on few ideas behind on how it has been applied to design man-made artifacts, demonstrating the usefulness of the study.</p><p>Figure 43, provides evidences pointing out the knowledge of <em>“golden ratio”</em> from the time of Leonardo da Vinci and its application in some arts produced during renaissance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/0*8Ew-9mBTUS62HEvA" /><figcaption><strong>Figure 44 — Butterflies (Drawn based on Measurements derived from Golden Ratio)</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*Zjob9HT_ribhLUwD" /><figcaption><strong>Figure 45 — Mollusk Shell (Drawn based on Measurements derived from Golden Ratio)</strong></figcaption></figure><p>Figures 44 and 45; illustrate 2 naturalistic paintings (butterflies and a mollusk shell) drawn by a Venezuelan architect <a href="https://www.rafael-araujo.com/">Rafael Araujo</a>, in which the initial design sketch is based on proportions derived from <em>“golden ratio”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/0*Wou8mWCqg2436wZt.jpg" /><figcaption><strong>Figure 46 — Using Golden Ratio in Computer Graphic Design</strong></figcaption></figure><p>As stated during the beginning of this article the knowledge of <em>“golden ratio” </em>is universal and hence could be applied from man-made Arts to all disciplines of engineering. Figure 46, illustrates how <em>“golden ratio”</em> is applied in software engineering for designing logos of 3 popular trade brands.</p><p>In fact you could derive novel design concepts on your current corporate website making it more attractive, Naturalistic and user-friendly. Application of “golden ratio” for website design is a topic that needs to be discussed in separate. It will be an extremely pleasant learning experience, based on the knowledge gained from this article. For those who want to take up the challenge you can read it all <a href="https://medium.com/lexicon-digital/golden-ratio-a-swiss-army-knife-for-carving-beauty-attraction-into-your-own-website-b86b01bd9255">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50829526e154" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golden Ratio: A Swiss-Army-Knife for carving Beauty & Attraction into your own Website]]></title>
            <link>https://medium.com/lexicon-digital/golden-ratio-a-swiss-army-knife-for-carving-beauty-attraction-into-your-own-website-b86b01bd9255?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b86b01bd9255</guid>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[golden-ratio]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[beauty]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Tue, 25 Feb 2020 07:12:46 GMT</pubDate>
            <atom:updated>2020-02-26T22:34:32.524Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Rj_A7qSbDNUR8wAv.gif" /></figure><p>What do you think <strong>beauty</strong> is? A beautiful flower? A beautiful building? Is it <strong>subjective</strong> from person to person? Whom would you perceive as a beautiful girl? Is beauty about being of a certain colour? Can it be measured? Is there a secret formula for carving beauty in any design?</p><p>Most of the above questions didn’t carry answers until recent times, in fact we’ve defined a distinct area from Science termed <strong>“Aesthetics”</strong>, to distinguish what is subjective and that can’t be measured based on a universal standard scale. The never-ending curious research with modern Mathematics has been able to unlock the secrets behind how our eyes and brain perceive beauty in a quantitatively re-presentable manner.</p><p>This article is an attempt to introduce the <strong>“golden ratio”</strong> and its amazing involvement in Nature for defining <strong>“beauty”</strong> in the human mind. Further, the focus of the final section is to provide elaborated tips on how to introduce beauty into web design using the concepts based on the <strong>golden ratio</strong>.</p><h3><strong>Golden Ratio</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*_bUq6jzjKK8M-_wk-VsvXA.png" /><figcaption><strong>Figure 1 — Golden Ratio Definition</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*tda18Y8KkpcLkArwHE0xTA.png" /><figcaption><strong>Figure 2 — Golden Ratio Derivation</strong></figcaption></figure><p>Suppose we divide any single line into 2 non-equal parts, and the <strong>ratio of lengths</strong> between the longer and shorter part is <strong><em>x:1</em></strong>, the <strong>golden ratio</strong> (denoted by greek letter <strong>φ</strong>)is defined as the value of <strong><em>x</em></strong> in which the <strong><em>longer part length divided by shorter part length </em></strong>(a/b in Figure 1) is also <strong>equal</strong> to <strong><em>the total line length divided by longer part length </em></strong>([a+b]/a in Figure 1).</p><p>The value of the <strong>golden ratio</strong> (<strong>φ</strong>) is a constant which is approximately equal to <strong>1.618</strong>.</p><h3><strong>Forming Simple Shapes with Golden Ratio</strong></h3><p>Now that we know what the golden ratio is we can form various shapes out of it. Of course the simplest shape we could form is called a <strong>“golden rectangle”</strong>; a rectangle with <strong>width:length</strong> ratio being <strong>1:1.618</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*koMRAnTS0sTuOWR1.jpeg" /><figcaption><strong>Figure 3 — Golden Ratio in Taj Mahal</strong></figcaption></figure><p>Imagine a door or window in your house… Is the length of your door/window is the same as its width? Is the length twice its width? Or is the length roughly 1.618 times the width? Which configuration do you find most in doors or windows? Which configuration appears more appealing to the average eye? I think you guessed it already. It is when the length of the door or window is roughly 1.618 times its width.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/0*-MhfX_zoqdrY_GF-.png" /><figcaption><strong>Figure 4 — Golden Ratio from a Greek’s Eye</strong></figcaption></figure><p>In fact, if we observe several images of classical architectures it becomes amazingly evident the usage of <strong>1:1.618 ratio based rectangles</strong>, consciously or unconsciously. You may do a self exercise to find out how many significant edges in the buildings coincide with 1:1.618 rectangles that could be found in Figures 4 and 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SVW65JAuzq1-Rb0V.jpeg" /><figcaption><strong>Figure 5 — Taj Mahal elaborated with Golden Ratio</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*3y3WHC3DJeEI-r8H.gif" /><figcaption><strong>Figure 6 — </strong><a href="https://www.goldennumber.net/wp-content/uploads/beauty-face-jolie-zeta-jones-hurley-colgate-ryan.gif"><strong>Golden ratio proportions of the teeth/lips and nose in relation to<br>the distance from the pupils to the bottom of the chin</strong></a></figcaption></figure><p>Does the golden ratio present itself in a human face? What do you think of Figure 6? The golden ratio is the key formula behind carving beauty into everything in the universe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*TsHrk-coVyOOpwo-.jpeg" /><figcaption><strong>Figure 7 — Golden Acute Triangle (on left) and Golden Obtuse Triangle (on right)</strong></figcaption></figure><p>We could construct triangles seen in Figure 7, based on the golden ratio, in which 2 to 1 sides of the triangle having a ratio <strong>φ:1</strong>. The triangle on the left (Figure 7) is called the <strong><em>“golden acute triangle”</em></strong><em> </em>(since all 3 angles are less than 90 degrees).<em> </em>The triangle on the right (Figure 7) is called the <strong><em>“golden obtuse triangle”</em></strong><em> </em>(since one of the angles is greater than 90 degrees). These triangles can be used as foundational building blocks to form more complex shapes originating from the <strong>golden ratio (φ)</strong>.</p><h3><strong>Forming Complex Shapes with Golden Ratio</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/0*OdbrfOaRreXWdz4e.png" /><figcaption><strong>Figure 8 — A regular pentagon</strong></figcaption></figure><p>A regular pentagon (Figure 8), also called the <strong><em>“golden pentagon” </em></strong>is formed by combining <strong>2 golden obtuse triangles and 1 golden acute triangle</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*LBQ_1bCT5hhd_hRf.png" /><figcaption><strong>Figure 9 — Relationship between a golden pentagon and φ</strong></figcaption></figure><p>Figure 9 illustrates, how the formation of a golden pentagon (based on golden triangles in Figure 7), is amazingly related to <strong>φ</strong>. Although the pentagon appears as a different shape to us as a whole; a detailed analysis as in Figure 9 depicts the propagation of the golden ratio(φ) property during the formation of the overall shape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/0*orYRsgK3NULQPv_S.jpeg" /><figcaption><strong>Figure 10-Golden Pentagram</strong></figcaption></figure><p>The 5-sided star (illustrated blue in Figure 10), also called the <strong><em>“golden star pentagram”</em></strong>; is built by combining <strong>3 golden obtuse triangles together on the base of a golden pentagon.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKudDS4I46d1XJcaZyd4gA.png" /><figcaption><strong>Figure 11–Two Golden Pentagrams, rotated 180 degrees to each other, and coinciding into a single 2D shape forming a regular decagon</strong></figcaption></figure><p>The regular decagon (also called the <strong><em>“golden decagon”</em></strong>) is a polygon with 10 equal sides formed when 2 golden pentagrams rotated 180 Degrees apart coincide with each other (Figure 11).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/0*9GthAhr_pWOc9hEB.png" /><figcaption><strong>Figure 12 — Golden Decagon</strong></figcaption></figure><p>For a golden decagon, the <strong>ratio</strong> between <em>the distance to a vertex from the center</em> versus <em>the length of a side</em> is <strong>φ </strong>(1.618).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/0*tXKltI5pfyEwtl11.gif" /><figcaption><strong>Figure 13 — Golden Spiral: Definition</strong></figcaption></figure><p>Figure 13 illustrates an animation of a Nautilus shell. The proportion between the blue and white areas observed when traversing the spiral is aligned with 1:1.618 (1:φ), all the time (which is the definition for the <strong><em>“golden spiral”</em></strong>).</p><p>So that we know what is a “golden spiral”, the next question would be how to construct a golden spiral geometrically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/0*0eUSwc7_cWx3Pzgi.png" /><figcaption><strong>Figure 14 — Golden Spiral: Construction with Golden Acute Triangle</strong></figcaption></figure><p>One of the approaches to construct a “golden spiral” is to <strong><em>start from a golden acute triangle </em></strong><em>and</em><strong><em> recursively subdivide </em></strong><em>into</em><strong><em> smaller golden acute triangles</em></strong> (Figure 14).</p><p>A second approach to generate a golden spiral is using a set of shapes formed by <strong><em>“Fibonacci numbers” </em></strong>(Figure 15).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*px159BqDDWhEwbYQ.jpg" /><figcaption><strong>Figure 15 — Golden Spiral: Construction with Fibonacci Numbers</strong></figcaption></figure><p>For the laymen, <em>“Fibonacci numbers”</em> is a self-generating series in which; the first two numbers are 1, 1 and each number after that is the sum of the previous two numbers. As you can see in Figure 15, 1+1=2, 2+1=3, 3+2=5, 5+3=8, 8+5=13, 13+8 = 21 and so on…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*b8CkL5490mQaoTyS.png" /><figcaption><strong>Figure 16 — Fibonacci Series and Golden Ratio</strong></figcaption></figure><p>But why is the Fibonacci series connected with generating a golden spiral? In fact, nothing related to beauty escapes the golden ratio. As in Figure 16; when you divide any number in the Fibonacci series with the previous number (except during the first few cases), the answer coincides with the value of the golden ratio. (e.g. 34/21, 21/13, 13/8 and so on…)</p><h3><strong>Defining a Golden Ratio based Layout for your WebSite</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*pzw-ERLpA4LQbQdu.jpg" /><figcaption><strong>Figure 17 — Golden Ratio based Web Layout Starters</strong></figcaption></figure><p>Figure 17, provides several ideas in which you could initiate a cool web layout; by starting from a “golden rectangle” and evolving it to an artistic layout as a constructed “golden spiral” with sub-division based on Fibonacci proportional squares.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*Ks8bQzdVAQICj8PC.png" /><figcaption><strong>Figure 18 — A Golden Spiral based Web Layout</strong></figcaption></figure><p>A useful practical application is arranging widgets in a documentary or news website with different sizes based on the importance and priority of content in each item (Figure 18).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*ioUW6OoWExu2RwWi.jpg" /><figcaption><strong>Figure 19 — A Product WebSite with Tweets</strong></figcaption></figure><p>You could also use the “golden spiral” based sub-division within a web layout when designing a product website (Figure 19) with comments; to define areas dedicated for different roles (such as product information, tweet display, stats board etc…)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bGxikmNM9VhprTAZ.jpg" /><figcaption><strong>Figure 20 — Facebook Landing Page</strong></figcaption></figure><p>Figure 20, illustrates how the Facebook landing page adheres “golden spiral”.</p><h3><strong>Using “golden ratio” based Shapes to embed Web Content</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*IqptQOG0mHrLZREO.jpg" /><figcaption><strong>Figure 21 — Golden Pentagon</strong></figcaption></figure><p>Figure 21, illustrates how you could use multiple golden pentagrams as web content. This kind of a design could be used for describing steps in a customer supply chain, values of a company, goals of a project…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*IATZ7t9BW3UuQprB.jpg" /><figcaption><strong>Figure 22 — Golden Pentagons for a Metric Dashboard</strong></figcaption></figure><p>Multiple golden pentagons could be used to provide an attractive user experience for a 5-way metric dashboard (Figure 22).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*Mzvb6b9j0WV0JDkU.jpg" /><figcaption><strong>Figure 23 — Golden Pentagons with Semi-Golden Decagon</strong></figcaption></figure><p>A 10-step based business process workflow could be attractively visualised by combining golden pentagons with partial golden decagon shapes (Figure 23).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*NO86c15xixHy4GTO.gif" /><figcaption><strong>Figure 24 — Zooming out with Golden Spiral</strong></figcaption></figure><p>Golden Spiral with fibonacci proportioned squares, could be used to position objects in an animation that is continuously zooming in or zooming out.</p><p>I know that you’re curious to know the reason behind how the golden spiral construction fits perfectly in a zoom in and out animation.</p><p>In fact mathematics can explain anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*Dq4NkMlI87OjPHne.gif" /><figcaption><strong>Figure 25 — Golden Ratio as a Continued Fraction</strong></figcaption></figure><p>Mathematically, it could be proved that the value of the “golden ratio” (1.638…) is an infinitely continuous fraction (Figure 25). Hence the zooming based animation of the golden spiral is a 2-dimensional geometric interpretation of this continuous fraction.</p><h3><strong>Golden Ratio and Logos</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*_RSY0Ai09IZEFTlJ.jpg" /><figcaption><strong>Figure 26 — Golden Pentagram based Logo</strong></figcaption></figure><p>The golden pentagram (i.e. 5 sided star) is a very popular shape used to represent different things; including famous brands, sports teams worldwide (Figure 26).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*qYiC8LSMDC97IAt5.jpg" /><figcaption><strong>Figure 27 — Golden Ratio versus Popular Logos</strong></figcaption></figure><p>Figure 27, illustrates the relationship between the “golden ratio” and several well-known company logos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/0*Wq6fk1WKkuvWRGc-" /><figcaption><strong>Figure 28 — Complex Shapes with Fibonacci Circles</strong></figcaption></figure><p>Figure 28, shows some ideas in terms of modelling and interpreting any complex shape in nature using the Fibonacci radii based circles (see Figure 15 too).</p><p>In fact you can model or interpret any complex beautiful shape in nature with a little extra effort of research, including <a href="https://medium.com/@wimal.perera/finding-my-dream-girl-with-golden-ratio-31a95c7bf219">the beauty of the human face</a>.</p><h3><strong>Putting It Altogether</strong></h3><p>Any man-built entity (including your own business website), could be built in a better convincing manner; by applying lessons learnt from Nature and how they revolve with Mathematics and Engineering.</p><p>Interested in making your own business website, more accessible to customers with a better User Experience? <a href="https://lexicon.com.au/get-in-touch/">Contact Us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b86b01bd9255" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lexicon-digital/golden-ratio-a-swiss-army-knife-for-carving-beauty-attraction-into-your-own-website-b86b01bd9255">Golden Ratio: A Swiss-Army-Knife for carving Beauty &amp; Attraction into your own Website</a> was originally published in <a href="https://medium.com/lexicon-digital">Lexicon Digital</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding my dream girl with Golden Ratio]]></title>
            <link>https://wimal-perera.medium.com/finding-my-dream-girl-with-golden-ratio-31a95c7bf219?source=rss-b1da499622a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/31a95c7bf219</guid>
            <category><![CDATA[geometry]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[golden-ratio]]></category>
            <category><![CDATA[nature]]></category>
            <category><![CDATA[beauty]]></category>
            <dc:creator><![CDATA[Wimal Perera]]></dc:creator>
            <pubDate>Mon, 17 Feb 2020 21:46:22 GMT</pubDate>
            <atom:updated>2020-07-16T06:05:39.110Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding my dream girl with the ‘Golden Ratio’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*aua2mMa7ThZr0wATnTQH5A.jpeg" /></figure><p>What do you think <strong>beauty</strong> is? A beautiful flower? A beautiful building? Is it <strong>“subjective”</strong> from person to person? Whom would you perceive as a beautiful girl? A blonde girl with glistening hair? Then how come there are black female models like Naomi Campbell and Tyra Banks playing leading roles in the global modelling industry? Is beauty about being of a certain colour? Can it be measured? Can beauty be defined quantitatively as a standard scale ranging from 1 to 10?</p><p>Most of the above questions didn’t carry answers until recent times, in fact we’ve defined a distinct area from Science termed <strong>“Aesthetics”</strong>, to distinguish what is subjective and that can’t be measured based on a universal standard scale. The never-ending curious research with modern Mathematics has been able to unlock the secrets behind how our eyes and brain perceive beauty in a quantitatively re-presentable manner. This article is an attempt to introduce mathematics and its amazing involvement in Nature for defining <strong>“beauty”</strong> in the human mind.</p><p><strong>Golden Ratio</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*_bUq6jzjKK8M-_wk-VsvXA.png" /><figcaption><strong>Figure 1 — Golden Ratio Definition</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*tda18Y8KkpcLkArwHE0xTA.png" /><figcaption><strong>Figure 2 — Golden Ratio Derivation</strong></figcaption></figure><p>Suppose we divide any single line into 2 non-equal parts, and the <strong>ratio of lengths</strong> between the longer and shorter part is <strong><em>x:1</em></strong>, the <strong>golden ratio</strong> (denoted by greek letter <strong>φ</strong>)is defined as the value of <strong><em>x</em></strong> in which the <strong><em>longer part length divided by shorter part length </em></strong>(a/b in Figure 1) is also <strong>equal</strong> to <strong><em>the total line length divided by longer part length </em></strong>([a+b]/a in Figure 1).</p><p>The value of the <strong>golden ratio</strong> (<strong>φ</strong>) is a constant which is approximately equal to <strong>1.618</strong>.</p><p><strong>Forming Simple Shapes with Golden Ratio</strong></p><p>Now that we know what golden ratio is we can form various shapes out of it. Of course the simplest shape we could form is a <strong>“rectangle”</strong> with <strong>width:length</strong> ratio being <strong>1:1.618</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*l8A3KlafAvKdKE_CPEYDuw.jpeg" /><figcaption><strong>Figure 3 — Golden Ratio in Taj Mahal</strong></figcaption></figure><p>Imagine a door or window in your house… Is the length of your door/window is the same as its width? Is the length twice of its width? Or is the length roughly 1.618 times the width? Which configuration do you find most in doors/windows? Which configuration appears more appealing to the average eye? I think you guessed it already. It is when the length of the door/window is roughly 1.618 times its width.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*cqi8TL5ceFkTUNT5FHjWgg.png" /><figcaption><strong>Figure 4 — Golden Ratio from a Greek’s Eye</strong></figcaption></figure><p>In fact, if we observe several images of classical architectures it becomes amazingly evident the usage of <strong>1:1.618 ratio based rectangles</strong>, consciously or unconsciously. You may do a self exercise to find out how many significant edges in the buildings coincide with 1:1.618 rectangles that could be found in Figures 4 and 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOK_rmTc9VQhdXSNZ8vhPQ.jpeg" /><figcaption><strong>Figure 5 — Taj Mahal elaborated with Golden Ratio</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*4hSpWnYyQ8vDPUP9eO7GCw.gif" /><figcaption><strong>Figure 6— </strong><a href="https://www.goldennumber.net/wp-content/uploads/beauty-face-jolie-zeta-jones-hurley-colgate-ryan.gif"><strong>Golden ratio proportions of the teeth/lips and nose in relation to<br>the distance from the pupils to the bottom of the chin</strong></a></figcaption></figure><p>But wait!! We started with our quest for finding a dream girl. Does the golden ratio present itself in a human face? What do you think of Figure 6?</p><p><strong>Forming Complex Shapes with Golden Ratio</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*p2Y3uEu7rPKs9VDehQR2oQ.gif" /><figcaption><strong>Figure 7— </strong><a href="https://www.goldennumber.net/nautilus-spiral-golden-ratio/"><strong>Forming a Spiral with Golden Ratio</strong></a></figcaption></figure><p>We could form more complex shapes, other than a rectangle using the golden ratio based proportion <strong>1:1.618</strong>. A popular example is the <strong><em>“golden spiral”</em></strong>.</p><p>Figure 7 depicts an animation of a Nautilus shell. The proportion between the blue and white areas observed when traversing the spiral is approximately aligning with 1:1.618 (which is the <em>“golden spiral”</em>), all the time. Isn’t <strong>φ</strong> an amazing constant to appear not only in man-created architectural shapes, but also in shapes formed by nature?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*WCQl0k8YBsiourWgWjkw8Q.jpeg" /><figcaption><strong>Figure 8— Spirals in a Human Face</strong></figcaption></figure><p>Figure 8 illustrates how the spiral shape generated based on golden ratio proportions becomes evident within every little detail for a side view of the human face.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ruGx7Zc3lmT3R0e5Dx0ggQ.jpeg" /><figcaption><strong>Figure 9 &amp; 10 — Golden Triangles</strong></figcaption></figure><p>In addition to spirals we could construct triangles seen in Figures 9 &amp; 10, based on the golden ratio. The triangle on the left (Figure 9) is also called the <strong><em>“golden acute triangle”</em></strong><em> </em>(since all 3 angles are less than 90 degrees).<em> </em>The triangle on the right (Figure 10) is called as the <strong><em>“golden obtuse triangle”</em></strong><em> </em>(since one of the angles is greater than 90 degrees). These triangles can be used as foundational building blocks to form more complex shapes originating from the <strong>golden ratio (φ)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*kThp_u3n_RhShcmLKUoFbw.png" /><figcaption><strong>Figure 11 — Regular Pentagon</strong></figcaption></figure><p>A regular pentagon (Figure 11), is also called the <strong><em>“golden pentagon”.</em></strong> It is a composite shape formed by <strong>2 golden obtuse triangles and 1 golden acute triangle</strong>. Hence we could still form an argument that the pentagon shape appears beautiful (consciously or unconsciously) due to its strong relationship with the golden ratio. The US department of defence is called the “pentagon” since it is located in a building having a shape of a regular pentagon when viewed from the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*l5ejUc94RPKK7yaqWJIbbg.jpeg" /><figcaption><strong>Figure 12–Five Sided Star</strong></figcaption></figure><p>The 5-sided star (illustrated blue in Figure 12), also called <strong><em>“the golden star pentagram”</em></strong>; is built by combining <strong>3 golden obtuse triangles together on the base of a golden pentagon.</strong> It is a very popular shape globally for emblems, flags and overall sports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKudDS4I46d1XJcaZyd4gA.png" /><figcaption><strong>Figure 13–Two Golden Pentagrams, rotated 180 degrees to each other, and coinciding into a single 2D shape forming a regular decagon</strong></figcaption></figure><p>Here is a question for you… what would be the resulting 2D shape formed; if 2 pentagrams rotated 180 degrees to each other and coincided them in the same 2D plane? Both pentagrams rotated 180 degrees to each other have 5 vertices each (shown in blue in Figure 13). You guessed it right! 5 + 5 = 10. Hence the 2 pentagrams in Figure 13 form a <strong><em>“golden decagon”</em></strong> if they coincide into a single 2D plane (which is a regular polygon with 10 equal sides as in Figure 14).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*7PsZLVYn-6F15ry5c7PF3A.png" /><figcaption><strong>Figure 14 — Decagon with the Golden Ratio</strong></figcaption></figure><p>Surprisingly, for a decagon; the <strong>ratio</strong> between <em>the distance to a vertex from the center</em> versus <em>the length of a side</em> is <strong>φ </strong>(1.618). Isn’t mathematics amazing?</p><p>Have I forgotten to talk about beautiful women? Absolutely not. We’re very close to inventing a mathematical representation for defining beauty.</p><p><strong>Defining Beauty</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*C1XsDW5Y4bnA2VcdmdX3wQ.png" /><figcaption><strong>Figure 15 — Golden Decagon Matrix</strong></figcaption></figure><p>As illustrated in Figure 15, the <strong><em>entire subset of line segments</em></strong> formed after joining each of the 10 vertices (shown in red) in a regular decagon, is called the <strong><em>“golden decagon matrix”</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*bMO3FcNLmb2OJYZwmeb0xg.jpeg" /><figcaption><strong>Figure 16 — Decagon Flowers</strong></figcaption></figure><p>In fact the most beautiful things in Nature follow a geometry, adhering along the gridlines of the <em>“golden decagon matrix”</em> and curves formed with spirals derived from the golden ratio.</p><p>Can we construct a mathematical representation to assess beauty of a human face based on the golden spiral, golden triangles, pentagons and golden decagon matrix?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*3jbJ2_WLpA3nahDtW9cpgg.jpeg" /><figcaption><strong>Figure 17 — </strong><a href="https://www.beautyanalysis.com/about-mba/founder-ceo/"><strong>Dr Stephen Marquardt</strong></a></figcaption></figure><p>Fortunately, Dr. Stephen Marquardt from Southern California has already done this for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QUcAMSqXYmXlLEulBd8pFg.png" /><figcaption><strong>Figure 18 — </strong><a href="https://www.beautyanalysis.com/about-mba/founder-ceo/"><strong>Marquardt Beauty Mask (Phi Beauty Mask)</strong></a></figcaption></figure><p>The generalised beauty mask for the human face derived based on the decagon matrix and complex shapes formed from golden ratio (Figure 18) is called the <strong><em>“Marquardt Beauty Mask”</em></strong> or the <strong><em>“Phi Beauty Mask”</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7pDW02SjV-w_c3HP0-E6A.jpeg" /><figcaption><strong>Figure 19 — How Marquardt Mask was Derived</strong></figcaption></figure><p>Figure 19 is a brain-refresher for the reader illustrated from sub-figures a to g on how the <strong><em>“Marquardt Beauty Mask”</em></strong> was derived based on what we discussed up to this point.</p><p><strong>Applying the Marquardt Beauty Mask (Phi Beauty Mask)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*JT-LuEi61Z1tFvkTdh1OgA.png" /><figcaption><strong>Figure 20 — Jessica Simpson and Phi Beauty Mask</strong></figcaption></figure><p>Is Jessica Simpson beautiful? Well, yes at least for me. I know that most of you will say yes too. In fact when we compare the features of her face with the Phi Beauty Mask (Figure 20); the eyes, chin, nose, cheeks etc. are well aligned. Do you agree that this is why we see her as beautiful?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*JvE6kJVgsXaSq9fCTXFvpA.gif" /><figcaption><strong>Figure 21 — Beautiful Faces from Different Continents</strong></figcaption></figure><p>Figure 21 compares beautiful faces from different continents of the world with the Phi Beauty Mask and prove them to be beautiful. Do all of them appear beautiful for you too? Beauty is independent of race, ethnic group or skin colour. Hmm, I guess this explains why Naomi Campbell &amp; Tyra Banks compete head to head with Heidi Klum &amp; Paris Hilton in the modelling industry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*_Y7r8pUwcRcAWfwc7zwYaA.jpeg" /><figcaption><strong>Figure 22 — Bumping up the Beauty</strong></figcaption></figure><p>You can convert an average looking face to a beautiful face by slightly adjusting it using the Phi Beauty Mask. So be careful dating those beautiful women you see on dating sites, it could be a very different experience in person.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*AJWcz5caarq5-RIW3TRX8g.png" /><figcaption><strong>Figure 23 — The same theory applies to 1000s of years ago</strong></figcaption></figure><p>Is the Phi Beauty Mask applicable, only for the modern world? Absolutely not. The beauty of historical characters existed before thousands of years ago can be validated right, using the Phi Beauty Mask. We’re immortal. But <strong>φ</strong> is eternal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*o0MgXjfA4mKCBrqzszIGDg.png" /><figcaption><strong>Figure 24 — </strong><a href="https://www.beautyanalysis.com/research/evidence/beauty-ranges/"><strong>Defining a Scale for Beauty</strong></a></figcaption></figure><p>Is beauty a part of Aesthetics only? Isn’t it possible to define a standard scale from being very beautiful to extremely unattractive.</p><p>Figure 24 shows how you could compare and contrast faces with different levels of attraction against the Phi Beauty Mask. As you may notice, the further the attraction diminishes from a face; the further the original facial feature lines (such as nose, eyes, chin etc.) don’t comply with Phi Beauty Mask.</p><p>For all those girls curious to rate their own level of beauty and attraction at this point, the apple appstore hasn’t let you down. <a href="https://apps.apple.com/us/app/golden-ratio-face/id1249757954"><strong><em>“Golden Ratio Face”</em></strong></a> is a free app that you can try out yourself.</p><p>Oh! Sorry, I totally forgot. Last but not least, we’ve got to amend; <strong><em>“Snow-white and the 7 Dwarfs”</em></strong>. Would <em>“Mirror, Mirror! Who’s the fairest in the land?”</em> sound correct anymore? Absolutely not. The wicked queen would rather ask <em>“Mirror, Mirror! Who’s the most </em><strong><em>Phi Beauty Mask</em></strong><em> compliant in the land?”</em>. Fortunately for the prince and the 7 dwarfs, but unfortunately for the wicked queen; the ever sleeping Snow-white still has the highest <em>“Phi Beauty Mask”</em> compliance score among all in the land.</p><p>Meanwhile, the poor mirror is severely horrified about his future job security thinking the queen would throw away the mirror and buy a “Phi Beauty Mask” calculator; since the sleeping Snow-white is always the first, according to the Mirror’s assessment. Come on Mirror, life is not always the same. It’s time to get ready to live in the dungeons.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31a95c7bf219" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>