<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: The Mighty Programmer</title>
    <description>The latest articles on Forem by The Mighty Programmer (@dm8typrogrammer).</description>
    <link>https://forem.com/dm8typrogrammer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F287552%2Fcd4a795a-1a48-4f05-ad51-6e446b613085.png</url>
      <title>Forem: The Mighty Programmer</title>
      <link>https://forem.com/dm8typrogrammer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dm8typrogrammer"/>
    <language>en</language>
    <item>
      <title>Finding Balance in Software Development</title>
      <dc:creator>The Mighty Programmer</dc:creator>
      <pubDate>Mon, 01 Jun 2020 18:12:15 +0000</pubDate>
      <link>https://forem.com/dm8typrogrammer/finding-balance-in-software-development-485g</link>
      <guid>https://forem.com/dm8typrogrammer/finding-balance-in-software-development-485g</guid>
      <description>&lt;p&gt;Software development is not only about code. It is also about the process and the people around it. At the core, Product (Business) Managers and Developers turn the idea of Software into reality.&lt;/p&gt;

&lt;p&gt;In the philosophical view of Software development, there exist, two realms that affect the reality of Software: Product end and Technology end.&lt;/p&gt;

&lt;p&gt;These are different in the perception of an application:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An Application is a set of features that support a business function. - Product View&lt;/p&gt;

&lt;p&gt;An Application is a set of code, framework, libraries, services. - Developer View&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In contrast, these are also associated in a way that a change in one realm introduces change(s) in another realm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tap in Product Realm
&lt;/h2&gt;

&lt;p&gt;Customer Grievances, Competition Edge, UX improvements, Feedbacks and Law Changes: all these introduce changes. After a rigorous thought process (cost-benefit analysis), these changes are passed to developers to transform into code.&lt;br&gt;
At developers end, they might have to write new code or adjust with the existing codebase. The complexity of adjustment depends upon changes and existing code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;complexity = f(changes, existing_code)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Patching and re-patching of code&lt;/em&gt; disturb the structural balance of Software. When we patch, we are so focused on the piece of code to work that we ignore the overall stability of Software.&lt;/p&gt;

&lt;p&gt;Many times, fixing or enhancing one feature leads to disturbing other features. At one point in time, Software becomes a minefield.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do it right from the beginning
&lt;/h3&gt;

&lt;p&gt;A Software can only be well designed if we know what kind of changes to expect in future.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We are human; we can p̵r̵e̵d̵i̵c̵t̵ estimate a limited version of the future.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;This option might not always be viable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The external APIs are needed to be done right from the beginning; with time, it is harder to change interaction points because of uncontrolled dependants. It is nice to have developers with a mixed level of expertise or experience to corrected have better API design from the beginning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Continuous Refactoring or Refactor as you go
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Continuous Refactoring&lt;/em&gt; is a practical solution to keep the structure of Software in check. Sometimes, it may require re-structuring functionalities having no role with current business changes to keep Software structure stability or consistency.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is risk involved with Refactoring, which may cause breaking of existing features and restless nights.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Test-Driven Development
&lt;/h3&gt;

&lt;p&gt;Test-Driven Development (TDD) helps to mitigate breaking existing features risk. It helps to keep the existing-functionalities in check before and after refactoring.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You don’t need to follow the rule book of TDD. You just need to have some way of proving the existing features is not disturbed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Tap in Technology Realm
&lt;/h2&gt;

&lt;p&gt;New tools, code practices and technologies attract developers (as everyone wants to do better). When we start the development of any project, we freeze code practices: tools, frameworks, libraries and coding style. These practices stay constant for years.&lt;/p&gt;

&lt;p&gt;More the difference of the current Software development practice to new market trends, more it is harder to keep developers motivated on the current project running on old tracks. With time, the business value of the project becomes so much that it is harder to mess up with existing practices.&lt;/p&gt;

&lt;p&gt;At one point in the time, when developers quit; finding new developers to work on existing projects, are tougher to find.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Money becomes the only bait&lt;/em&gt;; after all, money solves all the problems. What for how long it would keep developers motivated?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2000%2F1%2AVTiL7IE0ATS4FhOPbiuP3Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2000%2F1%2AVTiL7IE0ATS4FhOPbiuP3Q.png" alt="balance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous Change
&lt;/h2&gt;

&lt;p&gt;I love to borrow some concepts from Design Thinking; whether it is the design of the code, practices or process, it should be ongoing.&lt;/p&gt;

&lt;p&gt;Change is an only forward option, and it does mean you readily accept the changes. It is all about maintaining a balance between stability and evolution.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In the software world, the definition of "right" is always temporary, contextual and opinionated. You have to (re)-discover and (re)-align your version of "right" before it is too late.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>productivity</category>
      <category>change</category>
      <category>career</category>
      <category>business</category>
    </item>
    <item>
      <title>Uploading a large file from web</title>
      <dc:creator>The Mighty Programmer</dc:creator>
      <pubDate>Tue, 31 Mar 2020 20:24:29 +0000</pubDate>
      <link>https://forem.com/dm8typrogrammer/uploading-a-large-file-from-web-1cjc</link>
      <guid>https://forem.com/dm8typrogrammer/uploading-a-large-file-from-web-1cjc</guid>
      <description>&lt;p&gt;Uploading files over the web is not an easy task. It involves considerable challenges in developing a solution that works for all file sizes. Uploading files are prone to failures, users drop, and security risks. On each failure, the file needs to be re-uploaded: which adversely affect associated user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Network Bandwidth &amp;amp; File Size
&lt;/h3&gt;

&lt;p&gt;The file upload takes considerable time: &lt;em&gt;more the time to upload, more the chances of failure or connection drop&lt;/em&gt;. &lt;strong&gt;With each failure, a file needs to be re-uploaded from the beginning with traditional methods.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The time to upload file can be understood by the following equation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;time_to_upload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;file_size&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;effective_bandwidth&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;overhead&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: The equation is oversimplified to explain relationships; it is not accurate; A variable is introduced for abstracting network overhead involved in the request.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It can be interpreted as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More the size ⇒ &lt;em&gt;more time.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Lesser the bandwidth ⇒ &lt;em&gt;more time.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;A large file on a slow network is the worst possible case.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Server Limitation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Http servers restrict the size of a file that can be uploaded. The standard limit is &lt;code&gt;2GB&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The operating system or file journalling system also imposes a limit on the file size they can handle.&lt;/li&gt;
&lt;li&gt;Disk space availability also a factor that controls maximum file size that can be uploaded.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Security Risks
&lt;/h3&gt;

&lt;p&gt;Uploading files is not free from Security Risks. The surface area of security risk depends upon the purpose of uploaded files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Denial of Service&lt;/strong&gt;: Server spends most of the time in serving a few requests; It expedites the hacking attempt in making Server go out &lt;em&gt;of service&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Infusion&lt;/strong&gt;: File upload easily enables code to be uploaded if unchecked, and it may lead to system hijacking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Overriding&lt;/strong&gt;: Client provided path can trick Server into replacing any critical file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution Idealization
&lt;/h2&gt;

&lt;p&gt;The following idea or can be proposed to increase the user experience in uploading files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pre Check&lt;/strong&gt;: Pre checking with Server before uploading whether it can handle the request or not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resumability&lt;/strong&gt;: File upload should resumes if there is a failure in connecting. It can only if Server or Client stores the state of upload progress.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verification&lt;/strong&gt;: File should be verified and scanned to eliminate any threat.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution Realization
&lt;/h2&gt;

&lt;p&gt;The following are iterations of implementation options &lt;em&gt;(Read in order)&lt;/em&gt;; these may be feasible or not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-checking
&lt;/h3&gt;

&lt;p&gt;Pre checking with Server is an additional network request; it may not be useful for small file size, but pre-checking for large files can be helpful.&lt;/p&gt;

&lt;h4&gt;
  
  
  With Http Header Expect: 100-continue¹
&lt;/h4&gt;

&lt;p&gt;Http header &lt;code&gt;Expect: 100-continue&lt;/code&gt; is probing header that used to determine whether Server can receive the current request with large message body or not. If Server accepts, it sends back &lt;code&gt;100&lt;/code&gt; else &lt;code&gt;417&lt;/code&gt; status code. If Server accepts, a second request is trigged to upload the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The beauty of this mechanism is that the second request automatically trigged by Http Client&lt;/strong&gt;. Unfortunately, It &lt;em&gt;cannot&lt;/em&gt; be set via programming means available: &lt;code&gt;fetch&lt;/code&gt; API or &lt;code&gt;XHR&lt;/code&gt; (Ajax) request. It can only be set by underlying user-agent or browser. In short, A programming effort &lt;em&gt;could not&lt;/em&gt; be made.&lt;/p&gt;

&lt;p&gt;Also, it is not well understood by many Servers implementations even if you somehow manage to set the header.&lt;/p&gt;

&lt;p&gt;Curl add this header on crossing &lt;code&gt;1024KB&lt;/code&gt; request body size³ when browsers add who knows.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a useful header to be practically useless. We need to pre-check through standard request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  With Two Separate Standard HTTP requests
&lt;/h4&gt;

&lt;p&gt;Overall uploading process can be conceptualized as two standard HTTP requests:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A file metadata need to be sent first.&lt;/li&gt;
&lt;li&gt;Based upon the server response file can be uploaded.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AVZgESv6oCodmkDZw7rIFig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AVZgESv6oCodmkDZw7rIFig.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to develop your error and success message or codes to realise this mechanism.&lt;/p&gt;

&lt;h4&gt;
  
  
  Without Reserving capacity
&lt;/h4&gt;

&lt;p&gt;Let’s assume a situation server has &lt;code&gt;1GB&lt;/code&gt; space left. Imagine, two clients asking to upload at the same time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2ApOBmn1GD5jrXbceIlrnVpg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2ApOBmn1GD5jrXbceIlrnVpg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both clients would get permission to upload, and after a while, both requests would be interrupted when Server gets &lt;code&gt;1 GB&lt;/code&gt; of combined data from both requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  With Reserved Capacity
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;What if Server could reserve capacity for a file that is about to be uploaded?&lt;/em&gt;&lt;br&gt;
It might look like a good idea, but it may not.&lt;/p&gt;

&lt;p&gt;Server would be dealing with &lt;em&gt;multiple requests&lt;/em&gt; at an instance, and not all of these would be successful. If unnoticed, Server may run out of storage space soon; even though Server having storage space conceptually. Also, any miscreant could learn it; place an attack on service.&lt;/p&gt;

&lt;p&gt;You need to devise a strategy to reclaim space carefully. If you are thinking to build &lt;em&gt;resumability&lt;/em&gt;, Server needs to wait for some time to reclaim corresponding space.&lt;/p&gt;
&lt;h4&gt;
  
  
  With Dynamic Capacity
&lt;/h4&gt;

&lt;p&gt;We live in a cloud computing world; where you don’t need to plan capacity (only if you have unlimited money 😌 ). Most of Cloud Providers provides &lt;em&gt;Object Storage&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Object Storage obscures scalability challenges associated with traditional file systems, and provide a simplified API to access entity named &lt;em&gt;Objects&lt;/em&gt;. An &lt;code&gt;object&lt;/code&gt; is semantically equivalent to a file.&lt;/p&gt;

&lt;p&gt;Modern databases too include &lt;em&gt;BLOB storage&lt;/em&gt; similar to Object Storage. Object Storages and Databases are alike in term of file system abstraction, but Databases offer their challenges of operations.&lt;/p&gt;
&lt;h3&gt;
  
  
  Resumability &amp;amp; Time
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Chunking
&lt;/h4&gt;

&lt;p&gt;When file size crosses a certain limit; it becomes necessary to split it and upload it in multiple requests.&lt;/p&gt;

&lt;p&gt;A file is a sequence of bytes. We can collate some bytes into &lt;em&gt;chunks&lt;/em&gt;. These chunks need to be individually uploaded by Client and combined by Server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;no_of_requests = file_size / chunk_size
time_to_a_request = chunk_size / bandwidth + overhead
time_to_upload  ~  time_to_a_request *  no_of_requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is a bit slower than &lt;em&gt;traditional mechanism&lt;/em&gt; as multiple requests increase networking overhead (ack), but it gives ultimate control in hand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provide the ability to upload large files over 2GB&lt;/li&gt;
&lt;li&gt;Resumability can be build using this idea.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chunking is effortful; it introduces additional metadata to be exchanged to build reliable file upload. HTML 5 provides many useful utilities to realise this mechanism.&lt;/p&gt;

&lt;p&gt;Here is a basic code snippet to illustrate the core implementation of chunking :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// file is instance of File API&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[input=file]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;totalSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;

&lt;span class="c1"&gt;// 10 KB : K = 1000 : Network transimission unit&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;noOfChunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalSize&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;noOfChunks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// upload  ajax request: hidden&lt;/span&gt;

  &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;offset&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;chunkSize&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;An article can be dedicated to design decisions associated with chunking; for now, you can explore &lt;a href="http://www.resumablejs.com/" rel="noopener noreferrer"&gt;Resumable.js&lt;/a&gt; and &lt;a href="https://tus.io/demo.html" rel="noopener noreferrer"&gt;Tus&lt;/a&gt; before you mind up to build your implementation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Compression
&lt;/h4&gt;

&lt;p&gt;A file can be compressed before uploading to Server. Compression is a &lt;em&gt;double edge sword&lt;/em&gt; as it may increase or decrease overall upload time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;total_to_upload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;compression_time&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;upload_time&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, Server must understand the compression algorithm in place; it is part of content-negotiation strategies.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You must have proof of concept if you introduce compression.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Security
&lt;/h3&gt;

&lt;p&gt;Scanning every uploaded file is an essential task. Additionally, you can consider the following security measurements:&lt;/p&gt;

&lt;h4&gt;
  
  
  Integrity Check
&lt;/h4&gt;

&lt;p&gt;A transferred file must be validated. &lt;em&gt;Checksum Checking&lt;/em&gt; is a well-known practice to verify file integrity. There are many hashing algorithms to choose from &lt;code&gt;MD5&lt;/code&gt;, &lt;code&gt;SHA-1&lt;/code&gt;, &lt;code&gt;SHA-256&lt;/code&gt; or many more. Whatever algorithm is chosen for whatsoever reasons, should be supported by both Client and Server implementation.&lt;/p&gt;

&lt;p&gt;HTTP Header: &lt;code&gt;Etag&lt;/code&gt; is used to exchange checksum. The calculated value must be transferred over the secure channel (TLS).&lt;/p&gt;

&lt;h4&gt;
  
  
  Blacklisting
&lt;/h4&gt;

&lt;p&gt;A file with executable permission can do more harm, especially if is application engine file like &lt;code&gt;.php&lt;/code&gt;, &lt;code&gt;.jsp&lt;/code&gt;, &lt;code&gt;.js&lt;/code&gt;, &lt;code&gt;.sh&lt;/code&gt; , and &lt;code&gt;.asp&lt;/code&gt;.&lt;br&gt;
Sandboxing or limited access is the key to protect the system.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At best, prevent users from uploading executable files.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Deep Content Disarm and Construction
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Deep Content Disarm and Construction&lt;/em&gt; (Deep CDR) is a technique of rebuilding files from the file parts by discarding harmful components. It makes sense for files like &lt;code&gt;pdf&lt;/code&gt;, &lt;code&gt;doc&lt;/code&gt; or &lt;code&gt;spreadsheet&lt;/code&gt; which allows embedded content. You can read about the technique in details &lt;a href="https://www.opswat.com/technologies/data-sanitization" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The system attributes: kind of files, maximum allowed file size affect the implementation choices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you are storing files in a traditional file system, then limit the file size. It would require a considerable number of requests to place a DOS attack and hopefully detectable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Devise a policy to define a time window to consider file upload failure and to eradicate partial-uploaded files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With Chunking, it would seem like you are repeating implementation of TCP at higher granularity.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Expect Header&lt;br&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When Curl sends 100 continue&lt;br&gt;&lt;br&gt;
&lt;a href="https://gms.tf/when-curl-sends-100-continue.html" rel="noopener noreferrer"&gt;https://gms.tf/when-curl-sends-100-continue.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;FileSize Limitation&lt;br&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/q/5053290/3076874" rel="noopener noreferrer"&gt;https://stackoverflow.com/q/5053290/3076874&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  FootNotes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bandwidth&lt;/strong&gt; is the amount of data that can be transferred in a unit of time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compression&lt;/strong&gt; is &lt;em&gt;information storage optimising encoding mechanism&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>architecture</category>
      <category>security</category>
      <category>design</category>
      <category>ux</category>
    </item>
    <item>
      <title>Custom Event with RxJS</title>
      <dc:creator>The Mighty Programmer</dc:creator>
      <pubDate>Wed, 29 Jan 2020 15:26:08 +0000</pubDate>
      <link>https://forem.com/dm8typrogrammer/custom-event-with-rxjs-1ccg</link>
      <guid>https://forem.com/dm8typrogrammer/custom-event-with-rxjs-1ccg</guid>
      <description>&lt;p&gt;Event-Based Programming is natural to any GUI based interface. HTML DOM¹ offers inbuilt Event Notification model, but &lt;strong&gt;&lt;em&gt;it is only useful when you are dealing with DOM Elements.&lt;/em&gt;&lt;/strong&gt; There is no support for non-DOM elements.&lt;/p&gt;

&lt;p&gt;Web applications have grown up in complexity with time; also, Javascript started participating in backend applications; which in turn made the world to see Javascript as more than HTML DOM manipulation gig.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article showcases building up custom event publisher-subscriber model on top of Reactive Programming for non-DOM elements.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Stage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Event-Driven Programming
&lt;/h3&gt;

&lt;p&gt;Event-Driven programming paradigm² introduces an intuitive flow of control based upon events.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Button is clicked =&amp;gt; show dialog.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Vocabulary
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;One who emits event can be called Event Publisher or Event Emitter or Event Dispatcher.&lt;/li&gt;
&lt;li&gt;One who listens to events is called Event Subscriber or Event Listener or Event Handler.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In general, &lt;strong&gt;Publisher-Subscriber&lt;/strong&gt; or &lt;strong&gt;PubSub&lt;/strong&gt; term is used collectively for event publisher and even subscriber.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reactive Programming
&lt;/h3&gt;

&lt;p&gt;Reactive Programming is a trending paradigm² these days. It is the processing of streams of data asynchronously. At core, reactive streams are written on top of the event-driven paradigm (?). You are going to build an event notification model on top of it by modelling events as a stream of data.&lt;br&gt;
&lt;a href="https://rxjs-dev.firebaseapp.com/"&gt;RxJS&lt;/a&gt; is a &lt;b&gt;r&lt;/b&gt;eactive programming e&lt;b&gt;x&lt;/b&gt;tension for &lt;b&gt;J&lt;/b&gt;ava&lt;b&gt;s&lt;/b&gt;cript. &lt;/p&gt;


&lt;h2&gt;
  
  
  In Action
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Problem Statement
&lt;/h3&gt;

&lt;p&gt;Consider modelling Thermostat, when room temperature crosses a certain threshold (30°C), AC would turn up, and windows would close.&lt;/p&gt;
&lt;h3&gt;
  
  
  Design
&lt;/h3&gt;

&lt;p&gt;Consider class Thermostat which encapsulates the logic of monitoring and publishes events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;above&lt;/code&gt;: when temperature crossed above 30°C &lt;em&gt;(threshold)&lt;/em&gt; from lower value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;below&lt;/code&gt;: when temperature crossed below or equal to 30°C &lt;em&gt;(threshold)&lt;/em&gt; from higher value.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Data Structure for holding event structure
&lt;/h3&gt;

&lt;p&gt;RxJS offers &lt;code&gt;Subject&lt;/code&gt; which can be used to emit events to multiple subscribers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Thermostat&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sensor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// data structure for holding subscriptions &lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;above&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="na"&gt;below&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Notice, there are two &lt;code&gt;Subject&lt;/code&gt; objects. You can also create a single &lt;code&gt;Subject&lt;/code&gt; object named &lt;code&gt;ThresholdCrossed&lt;/code&gt; with direction &lt;code&gt;above&lt;/code&gt; or &lt;code&gt;below&lt;/code&gt;. &lt;em&gt;Separating the event or combining the event is Design Concern which may depend upon many factors.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Subscription API for Event
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;on&lt;/code&gt; API for registering action based upon event.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// sanatize event left code&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Publishing Events
&lt;/h3&gt;

&lt;p&gt;Consider &lt;code&gt;monitor&lt;/code&gt; method which detects the rise and falls in temperature and publishes event accordingly.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;monitor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentTemperature&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// when temperature cross above THRESHOLD&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;currentTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;THRESHOLD&lt;/span&gt; 
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastRecordedTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;THRESHOLD&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// publish event&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;above&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentTemperature&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;currentTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;THRESHOLD&lt;/span&gt; 
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastRecordedTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;THRESHOLD&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// publish event&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;below&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentTemperature&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastRecordedTemperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentTemperature&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Subscribing for event 
&lt;/h3&gt;

&lt;p&gt;When the temperature is below 30°C then ac should go off, and the window should open; the opposite should happen for above event 30°C.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;thermostat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;below&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ac&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;thermostat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;above&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ac&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wiring all pieces together.&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/custom-event-rxjs-ho0n5"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Fiddling
&lt;/h2&gt;

&lt;p&gt;Any variation you make with the above code itself a pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeping event subscription data in the mediator class of Event-Emitter and Event-Listener is in-memory Event Bus pattern.&lt;/li&gt;
&lt;li&gt;If the event holds enough information that Event-Listener doesn't look back to Event-Emitter; it is Event Carried State Transfer pattern&lt;/li&gt;
&lt;li&gt;If you store all events in datastore, it is Event Sourcing pattern &lt;em&gt;(possible for backend side)&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;If there is a network partition between Event Publisher and Event Subscriber, then collectively, it is a Reactive System. It is build using queuing technologies &lt;em&gt;(possible for backend side)&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An event may contain, reference or link back to its source. In HTML DOM, each event has a field named target to point back to its source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;b&gt;D&lt;/b&gt;ocument &lt;b&gt;O&lt;/b&gt;bject &lt;b&gt;M&lt;/b&gt;odel is the parsed tree object representation of HTML document.&lt;/li&gt;
&lt;li&gt;A paradigm is a conceptual view of programming elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;About Event-Driven
&lt;a href="https://www.youtube.com/watch?v=STKCRSUsyP0&amp;amp;vl=en"&gt;https://www.youtube.com/watch?v=STKCRSUsyP0&amp;amp;vl=en&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Inheritance vs Composition</title>
      <dc:creator>The Mighty Programmer</dc:creator>
      <pubDate>Mon, 09 Dec 2019 05:01:09 +0000</pubDate>
      <link>https://forem.com/dm8typrogrammer/inheritance-vs-composition-51eg</link>
      <guid>https://forem.com/dm8typrogrammer/inheritance-vs-composition-51eg</guid>
      <description>&lt;p&gt;With the introduction of OOPs, Inheritance and Composition entered our senses and still confusing us.&lt;/p&gt;

&lt;p&gt;Choosing between &lt;em&gt;Composition&lt;/em&gt; and &lt;em&gt;Inheritance&lt;/em&gt; is not easy. Often, the decision depends upon the information which is not yet there.&lt;/p&gt;

&lt;p&gt;The structure of an application plays an essential role in adding changes. Composition and Inheritance are the building blocks of an application structure. It is imperative to know when to use which one.&lt;/p&gt;

&lt;h1&gt;
  
  
  Definition
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Inheritance&lt;/em&gt; is a way of reusing code by inheriting the structure from the referred class or Type. The referred class is called &lt;code&gt;parent&lt;/code&gt; or &lt;code&gt;base&lt;/code&gt; class and the referring class is called &lt;code&gt;child&lt;/code&gt; or &lt;code&gt;subclass&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Inheriting the structure&lt;/em&gt; suggests that subclass inherits public members (API) of the parent class. A subclass can override or add new behaviour or extend the existing behaviour of the parent class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Reference class &lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"animal walk"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Referring Class &lt;/span&gt;
&lt;span class="c1"&gt;// Cat class "inherits the structure" from the Animal class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="c1"&gt;// overriding existing behaviour&lt;/span&gt;
   &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"meow"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c1"&gt;// in main&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;cat&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Cat can "reuse" parent class behavior &lt;/span&gt;
&lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// meow&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Composition
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Composition&lt;/strong&gt; is a way of reusing code by interacting with the referred class &lt;em&gt;without any structural imposition&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Reference Class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Line&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"line drawing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Refering class &lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;sides&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Line&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;shapeDraw&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sides&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;side&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// code refering&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Decision Matrix
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Uniformity
&lt;/h2&gt;

&lt;p&gt;I had a situation to ignore JsonNaming annotation¹ provided by Jackson library (Java ecosystem). There is no direct API provided by the library to facilitate the same.&lt;/p&gt;

&lt;p&gt;A possible solution to have a new class dictating the desired functionality and injecting the new class object to the library. Luckily, the chosen library provides the API to inject custom class (Thanks to open-close design).&lt;/p&gt;

&lt;p&gt;Should I compose or inherit from the existing Class? - &lt;em&gt;inherit&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// class for library &lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JSONIntrospector&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// .. rest code&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;findNamingStrategy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AnnotatedClass&lt;/span&gt; &lt;span class="n"&gt;ac&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;JsonNaming&lt;/span&gt; &lt;span class="n"&gt;ann&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_findAnnotation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ac&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;JsonNaming&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ann&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ann&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// .. rest code&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;span class="c1"&gt;// custom class&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IgnoreJsonNaming&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;JSONIntrospector&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;findNamingStrategy&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AnnotatedClass&lt;/span&gt; &lt;span class="n"&gt;ac&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// inject code&lt;/span&gt;
&lt;span class="nc"&gt;ObjectMapper&lt;/span&gt; &lt;span class="n"&gt;mapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ObjectMapper&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;mapper&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setAnnotationIntrospector&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IgnoreJsonNaming&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Inheritance is more suitable in this context as it is expected to have structural similarity or uniformity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Composition would not have worked :&lt;/strong&gt;&lt;br&gt;
If I preferred to go with Composition, I would have to implement unnecessary methods to maintain structural similarity.&lt;/p&gt;

&lt;p&gt;Imagine, If in future, library developers add new behaviours to the referred Class, I would end up changing in the latest Class to have structural similarity.&lt;/p&gt;
&lt;h2&gt;
  
  
  Semantics
&lt;/h2&gt;

&lt;p&gt;Inheritance and Composition not only allow to reuse the code; they also define a relationship semantic between two classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Inheritance : is-a
Composition : has-* (* means any quantifier)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Apple &lt;em&gt;is a&lt;/em&gt; Fruit. (Inheritance)&lt;br&gt;
Apple &lt;em&gt;has&lt;/em&gt; seeds. (Composition)&lt;/p&gt;

&lt;p&gt;Human &lt;em&gt;is a&lt;/em&gt; mammal. (Inheritance)&lt;br&gt;
Human &lt;em&gt;has two&lt;/em&gt; hands. (Composition)&lt;/p&gt;

&lt;p&gt;These keywords assist in basic analysing the requirements.&lt;/p&gt;
&lt;h2&gt;
  
  
  Software Model: OOA/D
&lt;/h2&gt;

&lt;p&gt;Whenever we write software, we introduce so many concepts from Specification and Implementation point of view.&lt;/p&gt;

&lt;p&gt;Through rigorous analysis, these concepts end up with numerous classes. Shaping these classes (object decomposition) and connecting these classes become our primary responsibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Implementation Concepts: Factory, Manager, Service, Client, Provider
e.g. RestClient, EmailService, ValidtorFactory
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Sometimes, it is better to start with code at first, then evolve the design. You are free to play until the first release. Once the software is released, it is hard to reverse most of the decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multiple Concepts
&lt;/h3&gt;

&lt;p&gt;Inheritance does not befit well for multi-dimensions concepts or variants or attributes. If applied, it leads to Combinatorial Explosion of classes.&lt;/p&gt;

&lt;p&gt;Say, you are modelling Pizza (concept 1) with two allowed Toppings (concept 2) Onion and Tomato. If you choose Inheritance to connect Pizza and Topping, then you would end with four classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// with inheritance&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// without topping&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaWithTomatoToppings&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaWithOnionTopping&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaWithOnionAndTomatoToppings&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;140&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With Composition, two classes are sufficient.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// with composition&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;t1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Topping&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;t2&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Topping&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;basePrice&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;basePrice&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="o"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Topping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getPrice&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h1&gt;
  
  
  Takeaways
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;In Inheritance, the structure imposition introduces tight coupling between both connected classes; it restricts their future editing.&lt;/li&gt;
&lt;li&gt;Inheritance is well suited for uniformity.&lt;/li&gt;
&lt;li&gt;Inheritance does not great for multi-dimensions concepts or variants or attributes.&lt;/li&gt;
&lt;li&gt;Composition does not impose any structure of any of connected Class. It is a flexible option.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Disable specific annotation in Jackson
&lt;a href="https://github.com/FasterXML/jackson-databind/issues/133"&gt;https://github.com/FasterXML/jackson-databind/issues/133&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>oop</category>
      <category>architecture</category>
      <category>java</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
