<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Baqar Gogia on Medium]]></title>
        <description><![CDATA[Stories by Baqar Gogia on Medium]]></description>
        <link>https://medium.com/@bakargogia?source=rss-e41cd85aeeb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*2eX2ig4FfYfo2CXSyG41Vg.png</url>
            <title>Stories by Baqar Gogia on Medium</title>
            <link>https://medium.com/@bakargogia?source=rss-e41cd85aeeb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:24:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bakargogia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SOLID Android]]></title>
            <link>https://medium.com/@bakargogia/solid-android-850841952773?source=rss-e41cd85aeeb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/850841952773</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Baqar Gogia]]></dc:creator>
            <pubDate>Sun, 02 Sep 2018 18:24:26 GMT</pubDate>
            <atom:updated>2018-10-29T08:17:01.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*PX8mejpgityIR91UM10mkQ.jpeg" /><figcaption>OLID #1: The Single Responsibility Principle (SRP)</figcaption></figure><blockquote>A class should have one, and only one, reason to change.</blockquote><p>for more details, let’s assume we need an <strong>adapter </strong>of <strong>Recyclerview</strong>, as you probably already know<strong> </strong>an adapter takes the data from the data set and adapts it to a view. An implementation I’ve seen could look like this:</p><pre>// <strong>violation of single responsibility principle</strong></pre><pre><strong>public</strong> <strong>class</strong> <strong>ActorsRecyclerAdapter</strong> <strong>extends</strong> RecyclerView<strong>.</strong>Adapter<strong>&lt;</strong>ActorsRecyclerAdapter<strong>.</strong>ViewHolder<strong>&gt;</strong> <strong>{</strong><br> <br>  <strong>private </strong>List&lt;Actor&gt; actors;<br>  <strong>private int</strong> itemLayout;</pre><pre><strong>public</strong> ActorsRecyclerAdapter<strong>(</strong>List<strong>&lt;</strong>Actor<strong>&gt;</strong> actors<strong>,</strong> <strong>int</strong> itemLayout<strong>)<br> </strong>   <strong>{</strong><br>         <strong>this</strong>.actors = actors;<br>         <strong>this</strong>.itemLayout = itemLayout;<br>    <strong>}</strong><br> <br>    <strong>@Override</strong> <br>    <strong>public</strong> ViewHolder onCreateViewHolder<strong>(</strong>ViewGroup parent<strong>,</strong> <strong>int</strong> viewType<strong>)</strong> <br>    <strong>{</strong><br>      <strong>View </strong>v = <strong>LayoutInflater</strong>.from(parent.getContext())<br>                             .inflate(itemLayout, parent, <strong>false</strong>);         <br>      <strong>return new </strong>ViewHolder(v);<br>    <strong>}</strong><br> <br>    <strong>@Override</strong> <br>    <strong>public</strong> <strong>void</strong> onBindViewHolder<strong>(</strong>ViewHolder holder<strong>,</strong> <strong>int</strong> position<strong>)</strong> <strong>{</strong><br>     <strong>final</strong> Actor actor = actors.get(position);  <br>     holder.<strong>itemView</strong>.setTag(actor);<br>     holder.<strong>title</strong>.setText(actor.getTitle());  <br>     holder.<strong>rating</strong>.setText(actor.getRating()); <br>     String movieString = &quot;&quot;;  <br>     for (String str: actor.movies()) { <br>           movieString += str + &quot;, &quot;;        <br>     }     <br>     movieString = movieString.length() &gt; 0 ? <br>            movieString.substring(0, movieString.length() - 2) : genreStr;  <br>     holder.<strong>movies</strong>.setText(movieString);            <br>     Glide.with(holder.<strong>thumbNail</strong>.getContext())<br>          .load(actors.get(position)<br>          .getThumbnailUrl())<br>          .into(holder.<strong>thumbNail</strong>);<br>    <strong>}</strong><br> <br>    <strong>@Override<br>    public</strong> <strong>int</strong> getItemCount<strong>()</strong> <strong>{</strong><br>        <strong>return</strong> actors<strong>.</strong>size<strong>();</strong><br>    <strong>}</strong><br> <br>    <strong>public</strong> <strong>static</strong> <strong>class</strong> <strong>ViewHolder</strong> <strong>extends</strong> RecyclerView<strong>.</strong>ViewHolder <strong>{</strong><br>      <strong>@Bind</strong>(R.id.title) <strong>TextView </strong>title; <br>      <strong>@Bind</strong>(R.id.rating) <strong>TextView </strong>rating;        <br>      <strong>@Bind</strong>(R.id.movies) <strong>TextView </strong>movies; <br>      <strong>@Bind</strong>(R.id.thumbnail) <strong>ImageView </strong>thumbNail;<br> <br>      <strong>public</strong> ViewHolder<strong>(</strong>View itemView<strong>)</strong> <strong>{</strong><br>        <strong>super(</strong>itemView<strong>);<br>      </strong>  ButterKnife.bind(<strong>this</strong>, itemView);            <br>      <strong>}</strong><br>    <strong>}</strong><br><strong>}</strong></pre><p>The code above violates the Single Responsibility Principle. Coz the adapter’s <strong>onBindViewHolder </strong>method is not only mapping from an Movie object to the view, but is also performing data formatting as well. This violates the Single Responsibility Principle. The adapter should only be responsible for adapting an order object to its view representation. The <strong>onBindViewHolder </strong>is performing extra duties that it should not be. An updated <strong>onBindViewHolder</strong> method could look like this:</p><pre><strong>public</strong> <strong>class</strong> <strong>ActorsRecyclerAdapter</strong> <strong>extends </strong>RecyclerView<strong>.</strong>Adapter<strong>&lt;</strong>ActorsRecyclerAdapter<strong>.</strong>ViewHolder<strong>&gt;</strong> <strong>{</strong><br> <br>  <strong>private </strong>List&lt;Actor&gt; actors;<br>  <strong>private int</strong> itemLayout;<br> <br>    <strong>public</strong> ActorsRecyclerAdapter<strong>(</strong>List<strong>&lt;</strong>Actor<strong>&gt;</strong> actors<strong>,</strong> <strong>int</strong> itemLayout<strong>)<br>  </strong>  <strong>{</strong><br>         <strong>this</strong>.actors = actors;<br>         <strong>this</strong>.itemLayout = itemLayout;<br>    <strong>}</strong><br> <br>    <strong>@Override</strong> <br>    <strong>public</strong> ViewHolder onCreateViewHolder<strong>(</strong>ViewGroup parent<strong>,</strong> <strong>int</strong> viewType<strong>)</strong> <br>    <strong>{</strong><br>      <strong>View </strong>v = <strong>LayoutInflater</strong>.from(parent.getContext())<br>                             .inflate(itemLayout, parent, <strong>false</strong>);       <br>      <strong>return new </strong>ViewHolder(v);<br>    <strong>}</strong><br> <br>    <strong>@Override</strong> <br>    <strong>public</strong> <strong>void</strong> onBindViewHolder<strong>(</strong>ViewHolder holder<strong>,</strong> <strong>int</strong> position<strong>)</strong> <strong>{</strong><br>     <strong>final</strong> Actor actor = actors.get(position);  <br>     holder.<strong>itemView</strong>.setTag(actor);<br>     holder.<strong>title</strong>.setText(actor.getTitle());  <br>     holder.<strong>rating</strong>.setText(actor.getRating());   holder.<strong>movies</strong>.setText(<strong>ArraysUtil</strong>.movieListToString(actor.Movies()));          <em><br></em>     Glide.with(holder.<strong>thumbNail</strong>.getContext())<br>          .load(actors.get(position)<br>          .getThumbnailUrl())<br>          .into(holder.<strong>thumbNail</strong>);<br>    <strong>}</strong><br> <br>    <strong>@Override<br>    public</strong> <strong>int</strong> getItemCount<strong>()</strong> <strong>{</strong><br>        <strong>return</strong> actors<strong>.</strong>size<strong>();</strong><br>    <strong>}</strong><br> <br>    <strong>public</strong> <strong>static</strong> <strong>class</strong> <strong>ViewHolder</strong> <strong>extends</strong> RecyclerView<strong>.</strong>ViewHolder <strong>{</strong><br>      <strong>@Bind</strong>(R.id.title) <strong>TextView </strong>title; <br>      <strong>@Bind</strong>(R.id.rating) <strong>TextView </strong>rating;        <br>      <strong>@Bind</strong>(R.id.movies) <strong>TextView movies</strong>;  <br>      <strong>@Bind</strong>(R.id.thumbnail) <strong>ImageView </strong>thumbNail;<br> <br>      <strong>public</strong> ViewHolder<strong>(</strong>View itemView<strong>)</strong> <strong>{</strong><br>        <strong>super(</strong>itemView<strong>);<br>      </strong>  ButterKnife.bind(<strong>this</strong>, itemView);            <br>      <strong>}</strong><br>    <strong>}</strong><br><strong>}</strong></pre><h4>SOLID #2: The Open-Closed Principle (OCP)</h4><blockquote><em>Software entities (classes, modules, functions, etc…) should be open for extension, but closed for modification.</em></blockquote><p>What we are basically talking about here is to design our modules, classes and functions in a way that when a new functionality is needed, we should not modify our existing code but rather write new code that will be used by existing code. let’s dive to it, and show some code:</p><pre>// <strong>violation of Open closed principle</strong><br>// Rectangle.java<br><strong>public</strong> <strong>class</strong> <strong>Rectangle</strong> <strong>{</strong><br>    <strong>private</strong> <strong>double</strong> length<strong>;</strong><br>    <strong>private</strong> <strong>double</strong> height<strong>;</strong> <br>    <em>// getters/setters ... </em><br><strong>}</strong></pre><pre>// Circle.java<br><strong>public</strong> <strong>class</strong> <strong>Circle</strong> <strong>{</strong><br>    <strong>private</strong> <strong>double</strong> radius<strong>;</strong> <br>    <em>// getters/setters ...</em><br><strong>}</strong></pre><pre>// AreaFactory.java<br><strong>public</strong> <strong>class</strong> <strong>AreaFactory</strong> <strong>{</strong><br>    <strong>public</strong> <strong>double</strong> calculateArea<strong>(</strong>ArrayList<strong>&lt;</strong>Object<strong>&gt;...</strong> shapes<strong>)</strong> <strong>{</strong><br>        <strong>double</strong> area <strong>=</strong> 0<strong>;</strong><br>        <strong>for</strong> <strong>(</strong>Object shape <strong>:</strong> shapes<strong>)</strong> <strong>{</strong><br>            <strong>if</strong> <strong>(</strong>shape <strong>instanceof</strong> Rectangle<strong>)</strong> <strong>{</strong><br>                Rectangle rect <strong>=</strong> <strong>(</strong>Rectangle<strong>)</strong>shape<strong>;</strong><br>                area <strong>+=</strong> <strong>(</strong>rect<strong>.</strong>getLength<strong>()</strong> <strong>*</strong> rect<strong>.</strong>getHeight<strong>());</strong>                <br>            <strong>}</strong> <strong>else</strong> <strong>if</strong> <strong>(</strong>shape <strong>instanceof</strong> Circle<strong>)</strong> <strong>{</strong><br>                Circle circle <strong>=</strong> <strong>(</strong>Circle<strong>)</strong>shape<strong>;</strong><br>                area <strong>+=</strong> <br>                <strong>(</strong>circle<strong>.</strong>getRadius<strong>()</strong> <strong>*</strong> cirlce<strong>.</strong>getRadius<strong>()</strong> <strong>*</strong> Math<strong>.</strong>PI<strong>);</strong><br>            <strong>}</strong> <strong>else</strong> <strong>{</strong><br>                <strong>throw</strong> <strong>new</strong> RuntimeException<strong>(</strong>&quot;Shape not supported&quot;<strong>);</strong><br>            <strong>}</strong>            <br>        <strong>}</strong><br>        <strong>return</strong> area<strong>;</strong><br>    <strong>}</strong><br><strong>}</strong></pre><p>As we see above, this code smell like if we have a shape like Triangle or any other polygone, we’re going to be modifying the AreaFactory class over and over. And that’s violate the open closed principle. It is not closed for modification and it is not open to extension. And that’s really bad, so let’s fix that:</p><pre>// Open closed principle: <strong>good example</strong><br>// Shape.java<br><strong>public</strong> <strong>interface</strong> <strong>Shape</strong> <strong>{</strong><br>    <strong>double</strong> getArea<strong>();</strong> <br><strong>}<br></strong>// Rectangle.java<br><strong>public</strong> <strong>class</strong> <strong>Rectangle</strong> implements <strong>Shape{</strong><br>    <strong>private</strong> <strong>double</strong> length<strong>;</strong><br>    <strong>private</strong> <strong>double</strong> height<strong>;</strong> <br>    <em>// getters/setters ... <br>    </em><strong>@Override</strong><br>    <strong>public</strong> <strong>double</strong> getArea<strong>()</strong> <strong>{</strong><br>        <strong>return</strong> <strong>(</strong>length <strong>*</strong> height<strong>);</strong><br>    <strong>}<br>}<br></strong>// Circle.java<br><strong>public</strong> <strong>class</strong> <strong>Circle</strong> implements <strong>Shape{</strong><br>    <strong>private</strong> <strong>double</strong> radius<strong>;</strong> <br>    <em>// getters/setters ...<br></em><strong>   @Override</strong><br>    <strong>public</strong> <strong>double</strong> getArea<strong>()</strong> <strong>{</strong><br>        <strong>return</strong> <strong>(</strong>radius <strong>*</strong> radius <strong>*</strong> Math<strong>.</strong>PI<strong>);</strong><br>    <strong>}<br>}<br></strong>// AreaFactory.java<br><strong>public</strong> <strong>class</strong> <strong>AreaFactory</strong> <strong>{</strong><br>    <strong>public</strong> <strong>double</strong> calculateArea<strong>(</strong>ArrayList<strong>&lt;</strong>Shape<strong>&gt;...</strong> shapes<strong>)</strong> <strong>{</strong><br>        <strong>double</strong> area <strong>=</strong> 0<strong>;</strong><br>        <strong>for</strong> <strong>(</strong>Shape shape <strong>:</strong> shapes<strong>)</strong> <strong>{</strong><br>            area <strong>+=</strong> shape<strong>.</strong>getArea<strong>();</strong><br>        <strong>}</strong><br>        <strong>return</strong> area<strong>;</strong><br>    <strong>}</strong><br><strong>}</strong></pre><p>Now, if we need to add a new shape, the AreaFactory will not need to be changed because it is open for extension through the Shape interface.</p><h4>SOLID #3: The Liskov Substitution Principle (LSP)</h4><blockquote><em>Child classes should never break the parent class’ type definitions.</em></blockquote><p>As simple as that, a subclass should override the parent class’ methods in a way that does not break functionality from a client’s point of view. Here is a simple example to demonstrate the concept.</p><pre>// violation of <strong>Liskov&#39;s Substitution principle</strong></pre><pre>// <strong>Car.java<br>public interface Car</strong> {<br>  public <strong>void </strong>startEngine();<br>}</pre><pre>//<strong> Ferrari.java</strong></pre><pre><strong>public</strong> <strong>Ferrari </strong>implements <strong>Car </strong>{<br>  ...<br>  <strong>@Override<br>  public</strong> <strong>void </strong>startEngine<strong>()</strong> <strong>{</strong><br>         <strong>//logic ...</strong><br>  }<br>}<br>// <strong>Tesla.java</strong></pre><pre><strong>public</strong> <strong>Tesla </strong>implements <strong>Car</strong>{<br>  ...<br>  <strong>@Override<br>  public</strong> <strong>void </strong>startEngine<strong>()</strong> <strong>{<br>         if (!IsCharged)<br>            return;<br>       //logic ...</strong><br> <strong> </strong>}<br>}</pre><pre>//<strong> Make the call</strong><br><strong>public void </strong>letStartEngine(<strong>Car </strong>car) <strong>{<br>   </strong>car<strong>.</strong>startEngine<strong>();<br>}</strong></pre><p>As you can see in the code above, there are two classes of cars. One fuel car and one electric car. The electric car can only start if it’s charged .The <strong>LetStartEngine </strong>method will not work if a car is electric and not charged. This breaks the <strong>LSP</strong> principle since it must be Charged to be able to start as the IsCharged (which also is part of the contract) won’t be set as in the base class.</p><p>To solve this you can do something like this:</p><pre>// Make the call<br><strong>public void </strong>LetStartEngine(<strong>Car </strong>car) <strong>{</strong></pre><pre><strong>if (</strong>car<strong> instanceof </strong>Tesla<strong>) <br>       ((Tesla)car).</strong>TurnOnCar()<strong>;  <br>   </strong>car<strong>.</strong>startEngine<strong>();<br>}</strong></pre><p>But this violates the Open/Closed Principale, so the proper way is to automatically turn on the car in the StartEngine method like below:</p><pre>// Fix of <strong>Liskov&#39;s Substitution principle</strong></pre><pre><strong>public interface Car</strong> {<br>  public <strong>void </strong>startEngine();<br>}</pre><pre>//<strong> Ferrari.java</strong></pre><pre><strong>public</strong> <strong>Ferrari </strong>implements <strong>Car </strong>{<br>  ...<br>  <strong>@Override<br>  public</strong> <strong>double</strong> startEngine<strong>()</strong> <strong>{</strong><br>         <strong>//logic ...</strong><br>  }<br>}<br>// <strong>Tesla.java</strong></pre><pre><strong>public</strong> <strong>Tesla </strong>implements <strong>Car</strong>{<br>  ...<br>  <strong>@Override<br>  public</strong> <strong>double</strong> startEngine<strong>()</strong> <strong>{<br>         if (!IsCharged)<br>            </strong>TurnOnCar<strong>();<br>       //logic ...</strong><br> <strong> </strong>}<br>}</pre><pre>// <strong>Make the call</strong><br><strong>public void </strong>letStartEngine(<strong>Car </strong>car) <strong>{<br>   </strong>car<strong>.</strong>startEngine<strong>();<br>}</strong></pre><h4>SOLID #4: The Interface Segregation Principle (ISP)</h4><blockquote><em>The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use.</em></blockquote><p>This principale states that once an interface becomes too fat, it needs to be split into smaller interfaces so that client of the interface will only know about the methods that pertain to them. As you know, the Android <a href="http://developer.android.com/reference/android/view/View.html">View</a> class is the root superclass for all Android views. You name it, if it’s a Button, the root superclass is <a href="http://developer.android.com/reference/android/view/View.html">View</a>. Let’s dive to it, and show some code:</p><pre><strong>public</strong> <strong>interface</strong> <strong>OnClickListener</strong> <strong>{</strong> <br>    <strong>void</strong> onClick<strong>(</strong>View v<strong>);</strong><br>    <strong>void</strong> onLongClick<strong>(</strong>View v<strong>);</strong> <br>    <strong>void</strong> onTouch<strong>(</strong>View v<strong>,</strong> MotionEvent event<strong>);</strong><br><strong>}</strong></pre><p>As you can see, this interface contains three diffrent methods, assuming that we wanna get click from a button:</p><pre>// Violation of <strong>Interface</strong> <strong>segregation</strong> <strong>principle</strong><br>Button valid <strong>=</strong> <strong>(</strong>Button<strong>)</strong>findViewById<strong>(</strong>R<strong>.</strong>id<strong>.</strong>valid<strong>);</strong><br>valid<strong>.</strong>setOnClickListener<strong>(new</strong> View<strong>.</strong>OnClickListener <strong>{</strong><br>    <strong>public</strong> <strong>void</strong> onClick<strong>(</strong>View v<strong>)</strong> <strong>{</strong><br>       <em>// TODO: do some stuff...</em><br>       <br>    <strong>}</strong><br>    <br>    <strong>public</strong> <strong>void</strong> onLongClick<strong>(</strong>View v<strong>)</strong> <strong>{</strong><br>        <em>// we don&#39;t need to it</em><br>    <strong>}</strong></pre><pre>    <strong>public</strong> <strong>void</strong> onTouch<strong>(</strong>View v<strong>,</strong> MotionEvent event<strong>)</strong> <strong>{</strong><br>        <em>// we don&#39;t need to it</em></pre><pre><strong>}</strong> <br><strong>});</strong></pre><p>The interface is too fat because it’s forcing to implement all the methods, even if it doesn’t not need them. Let’s trying to fix them using <strong>ISP</strong>:</p><pre>// Fix of <strong>Interface Segregation principle<br>public</strong> <strong>interface</strong> <strong>OnClickListener</strong> <strong>{</strong> <br>    <strong>void</strong> onClick<strong>(</strong>View v<strong>);</strong><br><strong>}</strong></pre><pre><strong>public</strong> <strong>interface</strong> <strong>OnLongClickListener</strong> <strong>{</strong> <br>    <strong>void</strong> onLongClick<strong>(</strong>View v<strong>);</strong><br><strong>}</strong></pre><pre><strong>public</strong> <strong>interface</strong> <strong>OnTouchListener</strong> <strong>{</strong> <br>    <strong>void</strong> onTouch<strong>(</strong>View v<strong>,</strong> MotionEvent event<strong>);</strong><br><strong>}</strong></pre><p>know we can use the interface without implement some messy methods.</p><h4>SOLID #5: The Dependency Inversion Principle (DIP)</h4><blockquote><em>1. High-level modules should not depend on low-level modules. Both should depend on abstractions.<br>2. Abstractions should not depend upon details. Details should depend upon abstractions.</em></blockquote><p>Let’s start from the code. Many of us probably seen (or written) code like this:</p><pre><strong>// </strong>violation of <strong>Dependency&#39;s inversion principle</strong></pre><pre>// <strong>Program.java</strong><br>class <strong>Program</strong> {</pre><pre>	public void <strong>work</strong>() {<br>		// ....code<br>	}<br>}</pre><pre>// <strong>Engineer.java</strong></pre><pre>class <strong>Engineer</strong>{</pre><pre>	Program program;</pre><pre>	public void <strong>setProgram</strong>(Program p) {<br>		program = p;<br>	}</pre><pre>	public void <strong>manage</strong>() {<br>		program.work();<br>	}<br>}</pre><p>The problem with the above code is that it breaks the Dependency Inversion Principle ; namely item (1.) from above: <em>High-level modules should not depend on low-level modules. Both should depend on abstractions. </em>We have the <strong>Engineer </strong>class which is a high level class, and the low level class called <strong>Program</strong>.</p><p>Let’s assume the <strong>Engineer </strong>class is quite complex, containing very complex logic. And now we have to change it in order to introduce the new SuperProgram. Let’s see the disadvantages:</p><ul><li>we have to change the Engineer class (remember it is a complex one and this will involve time and effort to make the changes).</li><li>some of the current functionality from the engineer class might be affected.</li><li>the unit testing should be redone.</li></ul><pre>// <strong>Dependency Inversion </strong>Principle - Good example<br>interface <strong>IProgram </strong>{<br>	public void <strong>work</strong>();<br>}</pre><pre>class <strong>Program </strong>implements <strong>IProgram</strong>{<br>	public void <strong>work</strong>() {<br>		// ....code<br>	}<br>}</pre><pre>class <strong>SuperProgram </strong>implements <strong>IProgram</strong>{<br>	public void <strong>work</strong>() {<br>		//....code<br>	}<br>}</pre><pre>class <strong>Engineer</strong>{<br>	<strong>IProgram </strong>program;</pre><pre>	public void <strong>setProgram</strong>(<strong>IProgram </strong>p) {<br>		program = p;<br>	}</pre><pre>	public void <strong>manage</strong>() {<br>		program.work();<br>	}<br>}</pre><p>In this new design a new abstraction layer is added through the <strong>IProgram</strong>Interface. Now the problems from the above code are solved(considering there is no change in the high level logic):</p><ul><li>Engineer class doesn’t require changes when adding SuperProgram.</li><li>Minimized risk to affect old functionality present in Engineer class since we don’t change it.</li><li>No need to redo the unit testing for Engineer class.</li></ul><p>As conclusion, we can said that the Single Responsibility Principle is about actors and high level architecture. The Open/Closed Principle is about class design and feature extensions. The Liskov Substitution Principle is about subtyping and inheritance. The Interface Segregation Principle (ISP) is about business logic to clients communication. And the Dependency Inversion Principale (DIP) is about leads or helps us respect all the other principles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=850841952773" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>