<?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: Elyess Eleuch</title>
    <description>The latest articles on DEV Community by Elyess Eleuch (@sightlessdog).</description>
    <link>https://dev.to/sightlessdog</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%2F546941%2Fa8b9d5c4-ef22-4462-a314-8b0f6898b0c6.jpg</url>
      <title>DEV Community: Elyess Eleuch</title>
      <link>https://dev.to/sightlessdog</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sightlessdog"/>
    <language>en</language>
    <item>
      <title>Clean Code</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Sun, 14 Feb 2021 18:46:04 +0000</pubDate>
      <link>https://dev.to/sightlessdog/clean-code-36d0</link>
      <guid>https://dev.to/sightlessdog/clean-code-36d0</guid>
      <description>&lt;p&gt;&lt;em&gt;Photo by Scott Umstattd on Unsplash&lt;/em&gt;&lt;br&gt;
Today I wanted to talk about clean code since we closed last week our SOLID series, I thought it would be perfect if I continued writing about clean code. &lt;/p&gt;
&lt;h1&gt;
  
  
  What is Clean Code?
&lt;/h1&gt;

&lt;p&gt;Clean Code is Code that can be read and directly understood. Reading code that turns out to be what we expected before reading it -&amp;gt; Simple and "Boring" code.&lt;br&gt;&lt;br&gt;
 The only photo that illustrates what I mean(in my opinion :p)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rXRSrbAw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/03ese518ghajsb3nxca2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rXRSrbAw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/03ese518ghajsb3nxca2.jpeg" alt="Clean Code"&gt;&lt;/a&gt;&lt;br&gt;
"Wtf metric should be zero"&lt;/p&gt;

&lt;p&gt;And what a code does is encapsulated inside functions, one of the most important aspects of it, in my opinion.&lt;/p&gt;

&lt;p&gt;But since we are talking about functions, I want to briefly explain why we write functions:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To decompose abstraction on so many levels and split the logic. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1&gt;
  
  
  Function Rules:
&lt;/h1&gt;
&lt;h2&gt;
  
  
  1 - Small:
&lt;/h2&gt;

&lt;p&gt;By small I mean that the function ideally shouldn’t exceed 10 lines, 20 in worst cases.&lt;br&gt;&lt;br&gt;
The code should be small so that we can easily understand the intent of the function by just reading it.&lt;br&gt;&lt;br&gt;
This is important especially when we are talking about big projects, where we have a lot of modules. In these projects, it is important to keep track of the logic and code in small easy to understand blocks, so that we don’t end up in total chaos.&lt;br&gt;&lt;br&gt;
Another Point, Smallness implies that blocks within if statements, else statements and while statements should be ideally one line long ( most probably a function call --&amp;gt; and it should document the intent ).   &lt;/p&gt;
&lt;h2&gt;
  
  
  2 - A function should do one thing: &lt;em&gt;and should do it well!&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;But what does one thing mean: if the code in the function is at the same level of abstraction&lt;br&gt;
(A level of abstraction is just a metaphor used to hide the tiny details of a subsystem. For example: let's say we have a part of our system that creates a list and then increments its values by ten. Creating the list is a level of abstraction and incrementing the value is another level.) &lt;br&gt;
then the function is doing one thing.&lt;br&gt;&lt;br&gt;
Or like uncle Bob says&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"if we still can extract more from a function then that function is doing more than one thing". &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In my words, if a function is reduced to the lowest then it’s doing one thing.   &lt;/p&gt;
&lt;h2&gt;
  
  
  3 -  We should use descriptive names:
&lt;/h2&gt;

&lt;p&gt;If it’s easy for us to name a function, in a way that we can document its intent, then our function is most probably well-written and easy to understand. If it’s the other way round, then you should probably review the function that you wrote. &lt;br&gt;
But sometimes, to document a function, its name can be too long, is that okay? Some people ask. Well, my answer to that is that before in the old days, people had to name functions using only 4 letters. That’s why I would say we should embrace the possibility that we can name our functions the way we want. Let’s avoid abbreviations. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"It is better to take many small steps in the right direction than to make a great leap forward only to stumble backward."- Louis Sachar &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and that is if I want to optimize time, and not spend on thinking about function names, this would only slow me down in the next days when I try to figure what the names that I wrote stand for.&lt;/p&gt;
&lt;h2&gt;
  
  
  4 -  Not a long number of arguments, the more arguments the more complication:
&lt;/h2&gt;

&lt;p&gt;Personally, I would put it like this. Deliver only the needed arguments. And if the arguments are not on the same level of abstraction then the function we're calling is doing more than one thing. &lt;br&gt;
Let's say I have a car that consists of 4 wheels, 5 chairs and a Steering Wheel. &lt;br&gt;
Let's suppose that our chairs are composed of springs. &lt;/p&gt;

&lt;p&gt;Then a call to the function car like this is to avoid :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wheel&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chair&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;spring&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;steeringWheel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because I would initialize two things (not at the same level) the car which is the higher level and the chair (lower level). &lt;/p&gt;

&lt;p&gt;I would rather call that function like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wheel&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;doneChair&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;steeringWheel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please notice that we didn't deliver something that is not necessary there and that would break another rule that we could have respected. &lt;/p&gt;

&lt;p&gt;Some People say: If we pass a  boolean to a function then we're clearly stating that this function is doing more than one thing.&lt;br&gt;
But this is not always true. Because sometimes we're maybe calling two different functions or just passing different params.  &lt;/p&gt;
&lt;h2&gt;
  
  
  5 - No side effects:
&lt;/h2&gt;

&lt;p&gt;What is meant with side effects is not what most people say, it doesn't have to be something hidden or unexpected, it can be but it is not the definition. &lt;/p&gt;

&lt;p&gt;A side effect is something changing somewhere else. In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment. And this type of functions ( with side effects ) are not testable, because they don’t have arguments to be tested. &lt;/p&gt;

&lt;p&gt;What do I mean by that?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;carString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Wheel Chair"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  
&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;carArray&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;carArray&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; 
&lt;span class="n"&gt;carArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;carString&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toCharArray&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now can we test this method? If yes? What would we test? With which arguments? The method doesn’t return anything, doesn’t accept arguments...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;carArray&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="n"&gt;carString&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toCharArray&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one looks way better. &lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion:
&lt;/h1&gt;

&lt;p&gt;Like I always say, these are not rules that we have to stick to, and make us judge each other. Sometimes bad code (not clean code) is necessary to keep some minimum level of understandability. &lt;/p&gt;

&lt;p&gt;Before caring about code we should care about each other. Do not refactor if that makes the code more difficult to understand. &lt;/p&gt;

&lt;h1&gt;
  
  
  Sources:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Side_effect_(computer_science)#:%7E:text=In%20computer%20science%2C%20an%20operation,the%20invoker%20of%20the%20operation"&gt;https://en.wikipedia.org/wiki/Side_effect_(computer_science)#:~:text=In%20computer%20science%2C%20an%20operation,the%20invoker%20of%20the%20operation&lt;/a&gt;. &lt;br&gt;
&lt;a href="https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29"&gt;https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29&lt;/a&gt; &lt;br&gt;
“Clean Code”, Robert C.  Martin &lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>java</category>
      <category>functional</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Revisiting the D in SOLID</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Sun, 07 Feb 2021 10:29:29 +0000</pubDate>
      <link>https://dev.to/sightlessdog/revisiting-the-d-in-solid-4795</link>
      <guid>https://dev.to/sightlessdog/revisiting-the-d-in-solid-4795</guid>
      <description>&lt;p&gt;&lt;em&gt;Photo by Pavel Nekoranec on Unsplash&lt;/em&gt;&lt;br&gt;
This is a continuation of the SOLID. In the last post, I covered the I and now we will be continuing with the last D. So if you didn't check the last post, feel free to click on the link: &lt;a href="https://dev.to/sightlessdog/revisiting-the-s-in-solid-adg"&gt;https://dev.to/sightlessdog/revisiting-the-s-in-solid-adg&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Dependency Inversion Principle
&lt;/h1&gt;

&lt;p&gt;The Dependency Inversion Principle is based on the Open/Closed Principle and the Liskov Substitution Principle. And it basically states that high-level modules shouldn't depend on low-level modules. &lt;br&gt;
Simply put, never depend on anything concrete, only depend on abstractions, which never depend on details but the other way round, details depend on abstractions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Iz8n4vtQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pjkce457fgrijm2hc1u1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Iz8n4vtQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pjkce457fgrijm2hc1u1.PNG" alt="Dependency Inversion Uml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see in the picture, inversion doesn't mean that the low-level module now depends on the higher-level one. Because in conventional application architecture, low-level components are designed to be consumed by the higher-level components.&lt;/p&gt;

&lt;p&gt;time for a simple example, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SteelWheel&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//properties and methods&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SteelWheel&lt;/span&gt; &lt;span class="n"&gt;wheel&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="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see our car class is forced to depend on a concrete implementation of wheel. And what does our principle say?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Never depend on anything concrete, only depend on abstractions&lt;br&gt;
We did violate our principle, right?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, you may be wondering right now, oh, the car class looks good, why should I care this much?.&lt;br&gt;
Mmmm, good question, but imagine this with me. You would want one day to change your SteelWheels to AlloyWheels. What would you do the car class?&lt;br&gt;
I hope that you are getting my point, if you change later the car class, you would violate the open/closed principle.&lt;br&gt;
The car class shouldn't care about the wheel being used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Wheel&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SteelWheel&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Wheel&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//properties and methods&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Wheel&lt;/span&gt; &lt;span class="n"&gt;wheel&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="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's how the low-level module and the high-level one depend on the abstraction.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope that this series was helpful. Wish you a good day!&lt;/p&gt;

&lt;h1&gt;
  
  
  Sources
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle"&gt;https://en.wikipedia.org/wiki/Dependency_inversion_principle&lt;/a&gt;&lt;br&gt;
Robert C. Martin “Principles of OOD”&lt;br&gt;
Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition&lt;br&gt;
&lt;a href="http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf"&gt;http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>cleancode</category>
      <category>solid</category>
      <category>java</category>
    </item>
    <item>
      <title>Revisiting the I in SOLID</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Sun, 31 Jan 2021 11:34:16 +0000</pubDate>
      <link>https://dev.to/sightlessdog/revisiting-the-s-in-solid-adg</link>
      <guid>https://dev.to/sightlessdog/revisiting-the-s-in-solid-adg</guid>
      <description>&lt;h6&gt;
  
  
  &lt;em&gt;Photo by Pavel Nekoranec on Unsplash&lt;/em&gt;
&lt;/h6&gt;

&lt;p&gt;This is a continuation of the SOLID. In the last post, I covered the L and now we will be continuing with the L. So if you didn't check the last post, feel free to click on the link: &lt;a href="https://dev.to/sightlessdog/revisiting-the-l-in-solid-116m"&gt;https://dev.to/sightlessdog/revisiting-the-l-in-solid-116m&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Interface Segregation Principle
&lt;/h1&gt;

&lt;p&gt;The Interface Segregation Principle was defined by Robert C. Martin several years ago while consulting for Xerox. He helped them change their printing system which was difficult to develop. &lt;/p&gt;

&lt;p&gt;He defines it as : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No client should be forced to depend on methods it does not use. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, Changing one method in a class shouldn't affect classes that don't depend on it. &lt;br&gt;
Or we can say larger interfaces should be split into smaller ones. &lt;/p&gt;
&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;Let's suppose 10 people work at a restaurant, our restaurantWorker class would look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;RestaurantWorker&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;washDishes&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;cook&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Out of the 10 people, there is this guy who doesn't know how to cook (he can only wash dishes or serve). Then the method cook() is not really relevant to him.  &lt;/p&gt;

&lt;p&gt;But sadly we have to implement the method cook() right? &lt;/p&gt;

&lt;h3&gt;
  
  
  To fix this, we would have to separate our interface into smaller ones
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Waiter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Cook&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;cook&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;DishWasher&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;washDishes&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;theGuyNoCook&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;DishWasher&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Waiter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;washDishes&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="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&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="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, we are free to implement only the relevant methods.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion:
&lt;/h1&gt;

&lt;h2&gt;
  
  
  The ISP is intended to keep away the strong coupling between the different parts of the system. And that's what makes the code we are writing easier to change, refactor and redeploy.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  Sources:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Interface_segregation_principle"&gt;https://en.wikipedia.org/wiki/Interface_segregation_principle&lt;/a&gt;&lt;br&gt;
Robert C. Martin “Principles of OOD”&lt;br&gt;
Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition&lt;br&gt;
&lt;a href="http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf"&gt;http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>cleancode</category>
      <category>solid</category>
      <category>java</category>
    </item>
    <item>
      <title>Revisiting the L in SOLID</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Sun, 24 Jan 2021 12:37:36 +0000</pubDate>
      <link>https://dev.to/sightlessdog/revisiting-the-l-in-solid-116m</link>
      <guid>https://dev.to/sightlessdog/revisiting-the-l-in-solid-116m</guid>
      <description>&lt;p&gt;Photo by Pavel Nekoranec on Unsplash&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vjb4Iezg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8gx6wc8b3wbjjboywcoh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vjb4Iezg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8gx6wc8b3wbjjboywcoh.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
This is a continuation of the SOLID. In the last post, I covered the O and now we will be continuing with the L. So if you didn't check the last post, feel free to click on the link: &lt;a href="https://dev.to/sightlessdog/revisiting-the-o-in-solid-4i84"&gt;https://dev.to/sightlessdog/revisiting-the-o-in-solid-4i84&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Liskov substitution principle
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Let z be a property provable about objects x of type T. Then z  should be true for objects y of type S where S is a subtype of T.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a nutshell: A has a property A, if B is a subtype of A then B has also the property A and B should behave the way A is expected to behave. And that means any derived class (B) should be able to substitute its parent class (A) without the consumer knowing it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;Let's suppose we have a car Class and two other classes Ferrari and Bugatti. Both of the cars are just..cars...sooo..they should behave like a normal car would do, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;speed&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="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bugatti&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Bugatti&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&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="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Ferrari&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Ferrari&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now let's suppose we want to customize a car by increasing its speed, usually, we would write a method inside the Car like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;increaseSpeed&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"You increased the speed of "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClass&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getSimpleName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;  &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" from "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please notice that increaseSpeed takes any car as a parameter.&lt;br&gt;
We didn't have to implement this method in each class (Ferrari and Bugatti) because they should behave the superclass (car) would. No Complications. And that's the Liskov Substitute Pattern. We replaced the car argument with one of the subtypes each time, and nothing has changed.&lt;br&gt;
Now let's check our results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You increased the speed of Bugatti from 200
You increased the speed of Ferrari from 210
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion:
&lt;/h1&gt;

&lt;p&gt;The Liskov Substitution Principle extends the open/closed principle by preventing breaking client code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Sources :
&lt;/h2&gt;

&lt;p&gt;Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition&lt;br&gt;
&lt;a href="http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf"&gt;http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf&lt;/a&gt;&lt;br&gt;
Robert C. Martin “Principles of OOD”&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle"&gt;https://en.wikipedia.org/wiki/Liskov_substitution_principle&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=rtmFCcjEgEw"&gt;https://www.youtube.com/watch?v=rtmFCcjEgEw&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.baeldung.com/solid-principles"&gt;https://www.baeldung.com/solid-principles&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>cleancode</category>
      <category>solid</category>
      <category>java</category>
    </item>
    <item>
      <title>Revisiting the O in SOLID</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Sun, 17 Jan 2021 11:33:35 +0000</pubDate>
      <link>https://dev.to/sightlessdog/revisiting-the-o-in-solid-4i84</link>
      <guid>https://dev.to/sightlessdog/revisiting-the-o-in-solid-4i84</guid>
      <description>&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F06lz22m0tbedulsvvsfs.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F06lz22m0tbedulsvvsfs.jpg" alt="good Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a continuation of the SOLID. In the last post, I covered the S and now we will be continuing with the O. So if you didn't check the last post, feel free to click on the link: &lt;a href="https://dev.to/sightlessdog/revisiting-the-s-in-solid-150e"&gt;https://dev.to/sightlessdog/revisiting-the-s-in-solid-150e&lt;/a&gt; &lt;/p&gt;

&lt;h1&gt;
  
  
  Open/Closed Principle:
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;“An entity should be open for extension, but closed  for     modification”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Bertrand Meyer, &lt;br&gt;
OO Software Construction&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Open for Extension: A module will be said to be open if it is still available for extension.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Closed for modification: This assumes that the module has been given a well-defined, stable description (the interface in the sense of information hiding).
&lt;/h2&gt;

&lt;h2&gt;
  
  
  we can achieve that by using a pattern, where high-level modules don't know anything about low-level details. The code is not rigid because nothing would recompile if we add new things, and the code is not fragile because you cannot break the code or let’s say the architecture doesn't let you break things.
&lt;/h2&gt;

&lt;p&gt;Let's use an example for this, everything would be easier to understand.&lt;br&gt;
let's suppose we have a cone class that looks like this &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwhf6zr8fpj6bdn1124wx.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwhf6zr8fpj6bdn1124wx.PNG" alt="Cone Class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And to make things more complicated, let's say we want to calculate it's volume, then the volume calculator class would look like this &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd44jy0lgd8svezti19f3.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd44jy0lgd8svezti19f3.PNG" alt="Volume"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Easy, right?
&lt;/h2&gt;

&lt;p&gt;But wait for a second, there's another client who doesn't have a cone but has Cube and wants to calculate the volume.&lt;/p&gt;

&lt;p&gt;An approach would be to do the logic in the calculator class &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff2j8lnjow4xfsb5wet4j.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff2j8lnjow4xfsb5wet4j.PNG" alt="Added Cube"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And as you can notice, this class (VolumeCalculator) isn't closed for modification. In order to extend it, we had to change it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now using the open/closed principle
&lt;/h2&gt;

&lt;p&gt;We would at first define a high-level module like Shape&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8s754bx0ajegd8obx62f.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8s754bx0ajegd8obx62f.PNG" alt="Shape"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then we would define our concrete shapes separately and by extending the abstract class.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc95ho393vmm08ruqsuh5.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc95ho393vmm08ruqsuh5.PNG" alt="NeWcONE"&gt;&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsnmkmbmt5tujppf21e8y.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsnmkmbmt5tujppf21e8y.PNG" alt="NewCube"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally, our Volume Calculator would look like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frj868412qev64vepjuw3.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frj868412qev64vepjuw3.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  And that's how we opened our class for extension by closing it for modification.
&lt;/h2&gt;

&lt;h1&gt;
  
  
  Sources :
&lt;/h1&gt;

&lt;p&gt;Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition&lt;br&gt;
&lt;a href="http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf" rel="noopener noreferrer"&gt;http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf&lt;/a&gt;&lt;br&gt;
Robert C. Martin “Principles of OOD”&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=zHiWqnTWsn4&amp;amp;t=2707s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=zHiWqnTWsn4&amp;amp;t=2707s&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=rtmFCcjEgEw" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=rtmFCcjEgEw&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.baeldung.com/solid-principles" rel="noopener noreferrer"&gt;https://www.baeldung.com/solid-principles&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>cleancode</category>
      <category>solid</category>
      <category>java</category>
    </item>
    <item>
      <title>Revisiting The S in SOLID</title>
      <dc:creator>Elyess Eleuch</dc:creator>
      <pubDate>Mon, 11 Jan 2021 21:09:32 +0000</pubDate>
      <link>https://dev.to/sightlessdog/revisiting-the-s-in-solid-150e</link>
      <guid>https://dev.to/sightlessdog/revisiting-the-s-in-solid-150e</guid>
      <description>&lt;p&gt;to start with, this is how I understood it. If you want to add something to it, feel free to contact me. I would be happy :).&lt;/p&gt;

&lt;h1&gt;
  
  
  WHAT IS SOLID?
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Single Responsibility (S)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Open/Closed (O)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Liskov Substitution (L)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Interface Segregation (I)&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Dependency inversion (D)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SOLID principles were first defined by Robert C. Martin in his book Design Principles and Design Patterns. Then the acronym SOLID was introduced by Michael Feathers.&lt;/p&gt;

&lt;p&gt;Martin’s and Feathers’ design principles encourage us to create more maintainable, understandable, and flexible software.&lt;br&gt;
But today we will be talking about the Single Responsibility Principle.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem that they address :
&lt;/h2&gt;

&lt;p&gt;The main problem that they tackle is working with legacy code.&lt;br&gt;
But wait for a second, what is the problem with legacy code?&lt;/p&gt;

&lt;p&gt;Here you go :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Re-reading code multiple times to get the part you need to change&lt;/li&gt;
&lt;li&gt;Hard to understand what a method does
*(Big giant methods that do everything )
*(or weird old names that do not refer to the logic of the method anymore)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With the legacy code, we spend more time reading than writing code&lt;/p&gt;

&lt;p&gt;Simply:&lt;/p&gt;

&lt;p&gt;It is most of the time bad code. And what leads to that?&lt;/p&gt;

&lt;h3&gt;
  
  
  The strategy that many of the startups adapt:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Constantly adding new features&lt;/li&gt;
&lt;li&gt;No formal process&lt;/li&gt;
&lt;li&gt;No time to worry about code structure ( daily releases, very dynamic)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And like uncle Bob says: Bad code slows us down, we want to be quick right, but not quick in a sloppy way.&lt;/p&gt;

&lt;p&gt;A developer should behave like a surgeon, steady, confident but have the deadline in mind.&lt;/p&gt;

&lt;h1&gt;
  
  
  Single Responsibility Principle:
&lt;/h1&gt;

&lt;h4&gt;
  
  
  “A class should have one, and only one reason to change”
&lt;/h4&gt;

&lt;p&gt;In other words, don’t put functions that change for different reasons in the same class.&lt;/p&gt;

&lt;p&gt;We want to create small classes with very specific names that are responsible for only one thing.&lt;/p&gt;

&lt;p&gt;Example: We have a car that has model, speed and interior components as properties.&lt;/p&gt;

&lt;p&gt;Our class would look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--POfQgJwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/etdckxk5rkyp7nkevod2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--POfQgJwi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/etdckxk5rkyp7nkevod2.PNG" alt="Car Class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And let’s suppose we want to print out the properties:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kfxo_I9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y23hcebilejm9hkq90vw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kfxo_I9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y23hcebilejm9hkq90vw.PNG" alt="Output Class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice here we don’t want to declare the printer methods inside the car class, but that would violate our principle.&lt;/p&gt;

&lt;p&gt;The Car class shouldn’t change because we want to output the text to some domain.com but only because the properties of the car changed.&lt;/p&gt;

&lt;p&gt;Benefits: Easier Testing, fewer dependencies&lt;/p&gt;

&lt;h1&gt;
  
  
  Sources :
&lt;/h1&gt;

&lt;p&gt;Meyer, B. (1997): Object-Oriented Software Construction, 2nd edition&lt;br&gt;
&lt;a href="http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf"&gt;http://www.cvc.uab.es/shared/teach/a21291/temes/object_oriented_design/materials_adicionals/principles_and_patterns.pdf&lt;/a&gt;&lt;br&gt;
Robert C. Martin “Principles of OOD”&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=zHiWqnTWsn4&amp;amp;t=2707s"&gt;https://www.youtube.com/watch?v=zHiWqnTWsn4&amp;amp;t=2707s&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=rtmFCcjEgEw"&gt;https://www.youtube.com/watch?v=rtmFCcjEgEw&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.baeldung.com/solid-principles"&gt;https://www.baeldung.com/solid-principles&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>oop</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
