<?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 Ahmed Abdelrahman on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Abdelrahman on Medium]]></description>
        <link>https://medium.com/@abdelrohman3351635?source=rss-52f3bf9d83a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oyjH94EVmDx9k_XRh0fWDg.jpeg</url>
            <title>Stories by Ahmed Abdelrahman on Medium</title>
            <link>https://medium.com/@abdelrohman3351635?source=rss-52f3bf9d83a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:49:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdelrohman3351635/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[Single Responsibility Principle]]></title>
            <link>https://medium.com/@abdelrohman3351635/single-responsibility-princip-1b7820c4dc82?source=rss-52f3bf9d83a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b7820c4dc82</guid>
            <dc:creator><![CDATA[Ahmed Abdelrahman]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 16:04:01 GMT</pubDate>
            <atom:updated>2023-02-18T15:03:14.304Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>What is Single Responsibility Principle meaning?</strong></h4><p>It is a fundamental principle of object-oriented programming that states that every class or module should have a single responsibility and should be responsible for only one part of a program’s overall functionality. This helps to promote code reusability, maintainability, and scalability.</p><h4><strong>How to achieve the Single Responsibility Principle with real examples?</strong></h4><p>If we have a class called Shape that has 3 methods (draw, color, print) this class is violating SRP because it has 3 tasks in one class so how can we achieve SRP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*XnA45HukM4Qdv9mDSmG-7Q.png" /></figure><p>we can let the method related to the class inside it without changing and separating other methods that are not associated with the class shape as you can see.</p><p>Keep “<strong>draw</strong>” method in the class without changing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZELS4VHTG84qvjnP2TnwWg.png" /></figure><p>Separating methods like “<strong>color</strong>” method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yACx0kDq1a4sqAt15dYRCA.png" /></figure><p>Separating the last method “<strong>print</strong>” method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4z2Tj0tEpl-A4LtdNc6oA.png" /></figure><p>So in this example, we achieve SRP</p><h3>Let&#39;s see another example 🤔</h3><p>If we have a class called “<strong>book</strong>” and I want to create an invoice from buying it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dEJr3bqCLsGflklCl_io8w.png" /></figure><p>when I create an invoice class it has 3 methods (calculateTotal, printInvoice, SaveToFile) in this class we violate SRP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_kU1e__3IVZWzPBJBIOcQ.png" /></figure><h4>How to achieve SRP in this example?</h4><p>we let <strong>“calculateTotal”</strong> method without any changing in same class</p><p>Separate <strong>“print”</strong> method in a class called <strong>“invoicePrinter”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Nx8BRoDxDFr3fZEClJRgg.png" /></figure><p>Separate <strong>“saveToFile”</strong> method in a class called <strong>“InvoiceStore”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*souz2vBO7dqhF1XSnTT0xA.png" /></figure><p>now we achieve the SRP and if you want any explanation you can check this video 👇👇</p><h3>Learn (SOLID) Single Responsibility Principle in Arabic</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAEJKP55ztCU&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAEJKP55ztCU&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/262b3f9d53ebd202279ea1821a838538/href">https://medium.com/media/262b3f9d53ebd202279ea1821a838538/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7820c4dc82" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>