<?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>DEV Community: faisol-riza</title>
    <description>The latest articles on DEV Community by faisol-riza (@faisolriza).</description>
    <link>https://dev.to/faisolriza</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%2F320400%2Fb1181aca-0085-4339-9e0d-2f2115a4b452.png</url>
      <title>DEV Community: faisol-riza</title>
      <link>https://dev.to/faisolriza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/faisolriza"/>
    <language>en</language>
    <item>
      <title>Single Responsibility Principle Simple Example</title>
      <dc:creator>faisol-riza</dc:creator>
      <pubDate>Mon, 02 Mar 2020 03:58:24 +0000</pubDate>
      <link>https://dev.to/faisolriza/single-responsibility-principle-simple-example-37d9</link>
      <guid>https://dev.to/faisolriza/single-responsibility-principle-simple-example-37d9</guid>
      <description>&lt;p&gt;(Cover Photo by David McEachan from Pexels)&lt;/p&gt;

&lt;p&gt;Good Day, guys!&lt;br&gt;
Single Responsibility Principle is the first part of the SOLID principle. In this article, I’ll try to explain the Single Responsibility Principle in with a simple example. So, we can get the philosophy of it. Then we can implement it in our daily coding activity.&lt;/p&gt;

&lt;p&gt;However, as a formality. Firstly, I will state it’s the definition from Wikipedia. Even though it is a little bit abstract, but it is still worth to get a theoretical definition of the Single Responsibility Principle.&lt;/p&gt;

&lt;p&gt;In Wikipedia, The Single Responsibility Principle means:&lt;/p&gt;

&lt;p&gt;“The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class, module or function. All its services should be narrowly aligned with that responsibility”&lt;/p&gt;

&lt;p&gt;We were all beginner and maybe it needs a little extra effort to understand the definition above.&lt;/p&gt;

&lt;p&gt;So, let’s jump to our illustration of the Single Responsibility Principle.&lt;/p&gt;

&lt;p&gt;Let’s say that once upon a time, there was a pharaoh. He wanted to build a pyramid. He had a great and smart commander. He ordered his commander to build one.&lt;/p&gt;

&lt;p&gt;Then the commander started to design the pyramid, he made the blueprint of the building structure. After that, he contacted the material supplier to provide all material that he needed. After ensuring all work well, he started to manage the labour to build the pyramid.&lt;/p&gt;

&lt;p&gt;From this illustration above, we know how the Single Responsibility Principle was violated. Since the commander has all responsibility, from the design, arrange material supply and manage the labour. Of course, it was still possible to run. However, it wasn’t very adaptive and flexible. Moreover, it can cause high complexity.&lt;/p&gt;

&lt;p&gt;Afterwards, the commander read a paper from Uncle Bob (Robert C Martin) about software design principle. And he interested to implement the Single Responsibility Principle. He hired several managers, and breakdown the responsibilities to departments. Each manager led a department and responsible for specific jobs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0piemyYx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/3183150/pexels-photo-3183150.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0piemyYx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/3183150/pexels-photo-3183150.jpeg" alt="managers image"&gt;&lt;/a&gt;&lt;br&gt;
(Photo by fauxels from Pexels)&lt;/p&gt;

&lt;p&gt;Yeah, the commander implemented a basic form of Single Responsibility Principle. Now, do you get the picture of the Single Responsibility Principle? Give me your own words to define it. And please do not stuck to Wikipedia definition, but we make it as a reference.&lt;/p&gt;

&lt;p&gt;Next, let’s try to translate it to simple pseudocode. &lt;/p&gt;

&lt;p&gt;Before implementing the Single Responsibility Principle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="c1"&gt;//Design works&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;pyramidLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;pyramidWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;pyramidHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;totalAreaPyramid&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CalculatePyramidArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pyramidLength&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pyramidWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pyramidHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;materialSupply&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CalculateMaterialSupply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalAreaPyramid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;totalLabor&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CalculateTotalLabor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalAreaPyramid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalAreaPyramid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;materialSupply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;totalLabor&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;After implementing the Single Responsibility Principle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="c1"&gt;//Design responsibility&lt;/span&gt;
    &lt;span class="n"&gt;BuildingBluePrint&lt;/span&gt; &lt;span class="n"&gt;PyramidDesign&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BuildingBluePrint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildingTypeEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Pyramid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pyramidLength&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pyramidWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pyramidHeight&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;//Material supply responsibility&lt;/span&gt;
    &lt;span class="n"&gt;BuildingMaterial&lt;/span&gt; &lt;span class="n"&gt;PyramidMaterial&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MaterialBuilding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PyramidDesign&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;//Labor management responsibility&lt;/span&gt;
    &lt;span class="n"&gt;BuildingContstructionLabor&lt;/span&gt; &lt;span class="n"&gt;PyramidLabor&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PyramidLabor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PyramidDesign&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;//Let’s build the pyramid&lt;/span&gt;
    &lt;span class="n"&gt;Return&lt;/span&gt; &lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PyramidDesign&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PyramidMaterial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PyramidLabor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The code above is not working code, I just try to give the picture of the Single Responsibility Principle. Please let me know if you have any feedback, both for my explanation or for may pseudo code.&lt;br&gt;
Next, I will continue with my second article about the Open Closed Principle.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Difference Between Recursion and Iteration</title>
      <dc:creator>faisol-riza</dc:creator>
      <pubDate>Mon, 20 Jan 2020 04:32:05 +0000</pubDate>
      <link>https://dev.to/faisolriza/difference-between-recursion-and-iteration-41d4</link>
      <guid>https://dev.to/faisolriza/difference-between-recursion-and-iteration-41d4</guid>
      <description>&lt;p&gt;What is the difference between recursion and iteration? Both recursion and iteration are running instruction repeatedly. However, they are totally different. At the first time I was also a little bit confuse. But after read some article and reference, finally I understand. I will summarize it for you and make it very simple to be understood.&lt;/p&gt;

&lt;p&gt;Recursion is call a function from inside it's function. This will make a repetitive process.&lt;/p&gt;

&lt;p&gt;We can take example a film titled "Inception" as a recursion process. In this film, the actor Leonardo DiCaprio as Dominic Cobb, and his team must go inside into someone's dream. If the mission is not succeed, they must go into deeper dream. And it happen repeatedly until they accomplish the mission.&lt;/p&gt;

&lt;p&gt;So recursion is somehow go deeper inside by repeatedly doing such a function from inside the function.&lt;/p&gt;

&lt;p&gt;Next, what is iteration? Even though it has similarity with recursion in term of repeated. But it has different meaning. Iteration is doing instruction repeatedly within a function.&lt;/p&gt;

&lt;p&gt;For example, when our mom are making soup with love, she cuts the carrots repeatedly until they all be cut. So, she will chop the carrots  for more than once, in order to make delicious soup.&lt;/p&gt;

&lt;p&gt;I hope my explanation can be understood in a very easy way.&lt;/p&gt;

</description>
      <category>recusrion</category>
      <category>iteration</category>
      <category>recursionvsiteration</category>
    </item>
  </channel>
</rss>
