<?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 Cihan Karagoz on Medium]]></title>
        <description><![CDATA[Stories by Cihan Karagoz on Medium]]></description>
        <link>https://medium.com/@cihankaragoz?source=rss-7f450fd0909b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YRZe1dBknLEKaO3T</url>
            <title>Stories by Cihan Karagoz on Medium</title>
            <link>https://medium.com/@cihankaragoz?source=rss-7f450fd0909b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 10:17:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cihankaragoz/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[ABAP Clean Code: The Power of Single Level of Abstraction]]></title>
            <link>https://medium.com/@cihankaragoz/abap-clean-code-the-power-of-single-level-of-abstraction-ee48700c9ed6?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee48700c9ed6</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Sun, 04 May 2025 13:54:35 GMT</pubDate>
            <atom:updated>2025-05-04T13:54:35.183Z</atom:updated>
            <content:encoded><![CDATA[<p>When we talk about clean code, we often focus on big, structured principles like SOLID. But there’s another rule — often overlooked — that’s just as critical:<br> <strong>Single Level of Abstraction</strong>.</p><p>This idea may not have its own acronym, but it’s one of the most powerful ways to make your code more understandable, testable, and maintainable.</p><p>Let’s explore what it means and why it matters especially in the world of ABAP.</p><h3>What Is Single Level of Abstraction?</h3><p>Imagine you’re getting into a car.</p><p>You press the start button, adjust the volume on the music system, and begin driving.<br>At no point do you see the <strong>transistors</strong>, <strong>amplifiers</strong>, or <strong>circuit boards</strong> behind that audio system. You interact with a <strong>clean, abstract interface</strong> — not the messy internals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWHiPRHvv_xn1SvlnsK5dg.jpeg" /></figure><p>Code should be the same.</p><p>When you’re reading a method, you shouldn’t have to jump between high-level business decisions and low-level data operations. Mixing them together creates confusion and cognitive overload.</p><p>That’s the essence of <strong>Single Level of Abstraction (SLA)</strong>:</p><blockquote><em>All statements in a method should be at the same conceptual level.</em></blockquote><h3>Why Is That Important?</h3><p>When a method mixes abstraction levels, it becomes harder to <strong>understand</strong>, <strong>change</strong>, and <strong>trust</strong>. Here’s why:</p><ul><li>You’re forced to constantly shift mental context, one moment thinking about business logic, the next about low-level assignments or technical operations.</li><li>It increases the <strong>risk of side effects</strong>, especially when you change low-level code embedded deep in business logic.</li><li>It makes methods longer and harder to <strong>name properly</strong>, which reduces their clarity and reusability.</li><li>It hinders <strong>unit testing</strong>, because testable business logic is buried inside implementation details.</li></ul><p>In short: <strong>Mixing abstraction levels clutters your thinking and your code.</strong></p><p>Let’s look at an example.</p><pre>METHOD calculate_discount.<br>  ASSIGN component-price TO &lt;price&gt;.<br>  IF &lt;price&gt; GT 1000.<br>    lv_discount = &lt;price&gt; * 0.1.<br>  ENDIF.<br>  CALL METHOD log_discount.<br>ENDMETHOD.</pre><p>This method includes:</p><ul><li>A low-level ASSIGN (data access)</li><li>Mid-level business logic (discount calculation)</li><li>A high-level action (logging)</li></ul><p>Reading this, you’re constantly switching between implementation detail and business logic. It’s like driving while occasionally being shown the inside of the car’s engine. Distracting, right?</p><h3>The Clean Version</h3><p>Let’s refactor the same logic with proper abstraction:</p><pre>METHOD calculate_discount.<br>  DATA(price) = get_price( ).<br>  DATA(discount) = determine_discount( price ).<br>ENDMETHOD.<br><br>METHOD get_price.<br>  ASSIGN component-price TO &lt;price&gt;.<br>  RETURN &lt;price&gt;.<br>ENDMETHOD.<br><br>METHOD determine_discount.<br>  IF price &gt; 1000.<br>    RETURN price * 0.1.<br>  ENDIF.<br>  RETURN 0.<br>ENDMETHOD.<br><br>METHOD log_discount.<br>   &quot; Just a placeholder for logging logic<br>  WRITE: / &#39;Discount calculated:&#39;, iv_discount.<br>ENDMETHOD.</pre><p>Now each method operates at <strong>one level of abstraction</strong>:</p><ul><li>calculate_discount is a clean, <strong>high-level orchestration method</strong>.</li><li>get_price handles the <strong>technical detail</strong> of accessing the component.</li><li>determine_discount contains <strong>business logic</strong> only.</li><li>log_discount is responsible for the <strong>logging concern</strong>.</li></ul><p>This is easier to read, easier to test, and easier to modify when requirements change.</p><h3>Why It Matters in ABAP</h3><p>ABAP systems, especially in large-scale SAP landscapes, are complex by nature. Clean code isn’t a luxury, it’s a necessity.</p><p>Following Single Level of Abstraction in ABAP helps you:</p><ul><li>Improve <strong>readability</strong> and onboarding</li><li>Enable <strong>unit testing</strong> of isolated logic</li><li>Increase <strong>reusability</strong> of smaller, focused methods</li><li>Make changes <strong>with confidence</strong></li></ul><h3>Final Thoughts</h3><p>Single Level of Abstraction may not be an official clean code principle, but it <strong>absolutely belongs in the conversation</strong>.</p><p>The next time you write or review an ABAP method, ask yourself:</p><blockquote><em>“Am I mixing different layers of logic here?”</em></blockquote><p>If the answer is yes, that’s your cue to refactor.</p><p>Because clean code isn’t just about structure, it’s about clarity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee48700c9ed6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code in ABAP — Dependency Inversion Principle (DIP)]]></title>
            <link>https://medium.com/@cihankaragoz/clean-code-in-abap-dependency-inversion-principle-dip-826d43402aa9?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/826d43402aa9</guid>
            <category><![CDATA[dependency-inversion]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Sat, 05 Apr 2025 18:20:51 GMT</pubDate>
            <atom:updated>2025-04-05T18:20:51.010Z</atom:updated>
            <content:encoded><![CDATA[<h3>Clean Code in ABAP — Dependency Inversion Principle (DIP)</h3><p>Welcome to the final part of the <strong>SOLID Principles in ABAP</strong> series. In this post, we’ll explore the <strong>Dependency Inversion Principle (DIP)</strong>, the principle that brings it all together by reducing coupling and improving flexibility in your applications.</p><h3>What is Dependency Inversion Principle?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJUSkqjBdv7ad0s5jlXM6g.jpeg" /></figure><blockquote><strong><em>High-level modules should not depend on low-level modules. Both should depend on abstractions.</em></strong><em><br></em><strong><em>Abstractions should not depend on details. Details should depend on abstractions.</em></strong></blockquote><p>This principle encourages us to design systems where high-level logic (e.g., business processes) doesn’t directly depend on low-level implementations (e.g., specific classes doing technical work). Instead, both depend on <strong>interfaces (abstractions)</strong>.</p><h3>The Problem: Tightly Coupled Design</h3><p>Let’s say we are developing a pay slip process that either sends an email or uploads to a DMS.</p><h3>❌ Without DIP</h3><pre>CLASS zcl_email_sender DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS: send_email IMPORTING iv_content TYPE string.<br>ENDCLASS.<br><br>CLASS zcl_email_sender IMPLEMENTATION.<br>  METHOD send_email.<br>    &quot; Logic to send email<br>    WRITE: / &#39;Email sent:&#39;, iv_content.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS zcl_payslip_processor DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS: process.<br>  PRIVATE SECTION.<br>    DATA: mo_sender TYPE REF TO zcl_email_sender.<br>ENDCLASS.<br><br>CLASS zcl_payslip_processor IMPLEMENTATION.<br>  METHOD process.<br>    mo_sender = NEW zcl_email_sender( ).<br>    mo_sender-&gt;send_email( &#39;Monthly Payslip&#39; ).<br>  ENDMETHOD.<br>ENDCLASS.</pre><p>In this version, the processor is tightly coupled to zcl_email_sender. If the delivery method changes, we must modify the processor class.</p><h3>✅ With DIP: Introducing an Abstraction</h3><p>Step 1: Define an Interface</p><pre>INTERFACE zif_payslip_delivery.<br>  METHODS: deliver IMPORTING iv_content TYPE string.<br>ENDINTERFACE.</pre><p>Step 2: Create Low-Level Implementations</p><pre>CLASS zcl_email_sender DEFINITION.<br>  PUBLIC SECTION.<br>    INTERFACES: zif_payslip_delivery.<br>ENDCLASS.<br><br>CLASS zcl_email_sender IMPLEMENTATION.<br>  METHOD zif_payslip_delivery~deliver.<br>    &quot; Email sending logic<br>    WRITE: / &#39;Delivered via Email:&#39;, iv_content.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS zcl_dms_uploader DEFINITION.<br>  PUBLIC SECTION.<br>    INTERFACES: zif_payslip_delivery.<br>ENDCLASS.<br><br>CLASS zcl_dms_uploader IMPLEMENTATION.<br>  METHOD zif_payslip_delivery~deliver.<br>    &quot; DMS upload logic<br>    WRITE: / &#39;Uploaded to DMS:&#39;, iv_content.<br>  ENDMETHOD.<br>ENDCLASS.</pre><p>Step 3: Refactor the High-Level Module</p><pre>CLASS zcl_payslip_processor DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS: constructor IMPORTING io_delivery TYPE REF TO zif_payslip_delivery,<br>             process.<br>  PRIVATE SECTION.<br>    DATA: mo_delivery TYPE REF TO zif_payslip_delivery.<br>ENDCLASS.<br><br>CLASS zcl_payslip_processor IMPLEMENTATION.<br>  METHOD constructor.<br>    mo_delivery = io_delivery.<br>  ENDMETHOD.<br><br>  METHOD process.<br>    mo_delivery-&gt;deliver( &#39;Monthly Payslip&#39; ).<br>  ENDMETHOD.<br>ENDCLASS.</pre><p>Step 4: Usage</p><pre>START-OF-SELECTION.<br><br>DATA(lo_delivery)  = NEW zcl_email_sender( ). &quot; or NEW zcl_dms_uploader( )<br>DATA(lo_processor) = NEW zcl_payslip_processor( lo_delivery ).<br>lo_processor-&gt;process( ).</pre><p>Now, zcl_payslip_processor depends only on the <strong>interface</strong>, not the actual implementation. Swapping between zcl_email_sender and zcl_dms_uploader requires no changes in the processor class.</p><h3>Benefits of Applying DIP</h3><p>✅ High-level logic is protected from low-level changes<br> ✅ Improved testability (you can inject mock classes)<br> ✅ Flexibility and extensibility<br> ✅ Clean separation of concerns</p><h3>Conclusion</h3><p>The Dependency Inversion Principle helps us decouple logic and makes our ABAP code more flexible and testable. By depending on <strong>interfaces instead of implementations</strong>, we can better respond to change and build more maintainable applications.</p><p>This marks the end of our SOLID series for ABAP!<br>We started with the <strong>Single Responsibility Principle</strong>, worked through <strong>OCP</strong>, <strong>LSP</strong>, and <strong>ISP</strong>, and now wrapped up with <strong>DIP</strong> for clean, modern ABAP development.</p><p>Thanks for reading and keep coding clean! 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=826d43402aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code in ABAP: Interface Segregation Principle (ISP)]]></title>
            <link>https://medium.com/@cihankaragoz/clean-code-in-abap-interface-segregation-principle-isp-4e675bd68f95?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e675bd68f95</guid>
            <category><![CDATA[interface-segregation]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 18:14:10 GMT</pubDate>
            <atom:updated>2025-02-19T18:37:17.057Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of software development, writing clean, maintainable, and scalable code is crucial. As an ABAP developer, adhering to the <strong>SOLID principles</strong> can help you achieve this goal. In my previous blogs, we explored the <strong>Single Responsibility Principle (SRP)</strong>, <strong>Open/Closed Principle (OCP)</strong>, and <strong>Liskov Substitution Principle (LSP)</strong>. Today, we’ll dive into the fourth principle: the <strong>Interface Segregation Principle (ISP)</strong>.</p><h3>What is the Interface Segregation Principle (ISP)?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*GNMrtpxT5knaBZM8y4pOgQ.png" /></figure><p>The Interface Segregation Principle states:</p><blockquote><strong><em>Clients should not be forced to depend on interfaces they do not use.</em></strong></blockquote><p>In simpler terms, it’s better to have many small, specific interfaces than one large, general-purpose interface. This principle encourages you to design interfaces that are tailored to the needs of the clients using them, avoiding unnecessary dependencies.</p><h3>Why is ISP Important in ABAP?</h3><p>In ABAP, interfaces are widely used to define contracts for classes. However, creating large, monolithic interfaces can lead to several issues:</p><ol><li><strong>Unnecessary Implementations</strong>: Classes implementing the interface may be forced to provide empty or irrelevant implementations for methods they don’t need.</li><li><strong>Tight Coupling</strong>: Changes to the interface can impact all implementing classes, even if they don’t use the modified methods.</li><li><strong>Reduced Readability</strong>: Large interfaces can make the code harder to understand and maintain.</li></ol><p>By applying ISP, you can create more modular, flexible, and maintainable ABAP code.</p><h3>Example: Violating ISP in ABAP</h3><p>Let’s start with an example that violates the Interface Segregation Principle. Suppose we have an interface ZIF_EMPLOYEE that defines methods for different types of employees:</p><pre>INTERFACE zif_employee PUBLIC.<br>  METHODS:<br>    calculate_salary,<br>    submit_timesheet,<br>    approve_expenses,<br>    write_code,<br>    test_code.<br>ENDINTERFACE.</pre><p>Now, let’s say we have two classes: ZCL_MANAGER and ZCL_DEVELOPER. Both implement the ZIF_EMPLOYEE interface:</p><pre>CLASS zcl_manager DEFINITION PUBLIC.<br>  PUBLIC SECTION.<br>    INTERFACES: zif_employee.<br>ENDCLASS.<br><br>CLASS zcl_manager IMPLEMENTATION.<br>  METHOD zif_employee~calculate_salary.<br>    &quot; Logic to calculate salary<br>  ENDMETHOD.<br><br>  METHOD zif_employee~submit_timesheet.<br>    &quot; Logic to submit timesheet<br>  ENDMETHOD.<br><br>  METHOD zif_employee~approve_expenses.<br>    &quot; Logic to approve expenses<br>  ENDMETHOD.<br><br>  METHOD zif_employee~write_code.<br>    &quot; Manager doesn&#39;t write code, so this is irrelevant<br>  ENDMETHOD.<br><br>  METHOD zif_employee~test_code.<br>    &quot; Manager doesn&#39;t test code, so this is irrelevant<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS zcl_developer DEFINITION PUBLIC.<br>  PUBLIC SECTION.<br>    INTERFACES: zif_employee.<br>ENDCLASS.<br><br>CLASS zcl_developer IMPLEMENTATION.<br>  METHOD zif_employee~calculate_salary.<br>    &quot; Logic to calculate salary<br>  ENDMETHOD.<br><br>  METHOD zif_employee~submit_timesheet.<br>    &quot; Logic to submit timesheet<br>  ENDMETHOD.<br><br>  METHOD zif_employee~approve_expenses.<br>    &quot; Developer doesn&#39;t approve expenses, so this is irrelevant<br>  ENDMETHOD.<br><br>  METHOD zif_employee~write_code.<br>    &quot; Logic to write code<br>  ENDMETHOD.<br><br>  METHOD zif_employee~test_code.<br>    &quot; Logic to test code<br>  ENDMETHOD.<br>ENDCLASS.</pre><p>In this example, both ZCL_MANAGER and ZCL_DEVELOPER are forced to implement methods they don’t need. This violates the Interface Segregation Principle.</p><h3>Applying ISP in ABAP</h3><p>To adhere to ISP, we can break down the ZIF_EMPLOYEE interface into smaller, more specific interfaces:</p><pre>INTERFACE zif_salary_calculator PUBLIC.<br>  METHODS:<br>    calculate_salary.<br>ENDINTERFACE.<br><br>INTERFACE zif_timesheet_submitter PUBLIC.<br>  METHODS:<br>    submit_timesheet.<br>ENDINTERFACE.<br><br>INTERFACE zif_expense_approver PUBLIC.<br>  METHODS:<br>    approve_expenses.<br>ENDINTERFACE.<br><br>INTERFACE zif_code_writer PUBLIC.<br>  METHODS:<br>    write_code.<br>ENDINTERFACE.<br><br>INTERFACE zif_code_tester PUBLIC.<br>  METHODS:<br>    test_code.<br>ENDINTERFACE.</pre><p>Now, we can implement only the relevant interfaces in each class:</p><pre>CLASS zcl_manager DEFINITION PUBLIC.<br>  PUBLIC SECTION.<br>    INTERFACES:<br>      zif_salary_calculator,<br>      zif_timesheet_submitter,<br>      zif_expense_approver.<br>ENDCLASS.<br><br>CLASS zcl_manager IMPLEMENTATION.<br>  METHOD zif_salary_calculator~calculate_salary.<br>    &quot; Logic to calculate salary<br>  ENDMETHOD.<br><br>  METHOD zif_timesheet_submitter~submit_timesheet.<br>    &quot; Logic to submit timesheet<br>  ENDMETHOD.<br><br>  METHOD zif_expense_approver~approve_expenses.<br>    &quot; Logic to approve expenses<br>  ENDMETHOD.<br>ENDCLASS.<br><br>CLASS zcl_developer DEFINITION PUBLIC.<br>  PUBLIC SECTION.<br>    INTERFACES:<br>      zif_salary_calculator,<br>      zif_timesheet_submitter,<br>      zif_code_writer,<br>      zif_code_tester.<br>ENDCLASS.<br><br>CLASS zcl_developer IMPLEMENTATION.<br>  METHOD zif_salary_calculator~calculate_salary.<br>    &quot; Logic to calculate salary<br>  ENDMETHOD.<br><br>  METHOD zif_timesheet_submitter~submit_timesheet.<br>    &quot; Logic to submit timesheet<br>  ENDMETHOD.<br><br>  METHOD zif_code_writer~write_code.<br>    &quot; Logic to write code<br>  ENDMETHOD.<br><br>  METHOD zif_code_tester~test_code.<br>    &quot; Logic to test code<br>  ENDMETHOD.<br>ENDCLASS.</pre><p>By segregating the interfaces, we ensure that each class only implements the methods it needs. This makes the code more modular, easier to maintain, and adheres to the Interface Segregation Principle.</p><h3>Benefits of ISP in ABAP</h3><ol><li><strong>Improved Maintainability</strong>: Smaller, focused interfaces are easier to understand and maintain.</li><li><strong>Reduced Coupling</strong>: Changes to one interface are less likely to impact unrelated classes.</li><li><strong>Better Reusability</strong>: Interfaces can be reused across different classes without forcing unnecessary implementations.</li><li><strong>Enhanced Readability</strong>: The code becomes more intuitive and self-documenting.</li></ol><h3>Conclusion</h3><p>The Interface Segregation Principle is a powerful guideline for designing clean and maintainable ABAP code. By breaking down large interfaces into smaller, specific ones, you can avoid unnecessary dependencies and create more modular systems. As you continue your journey as an ABAP developer, keep ISP in mind to write code that is not only functional but also elegant and scalable.</p><p>In the next blog, we’ll explore the final SOLID principle: the <strong>Dependency Inversion Principle (DIP)</strong>. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e675bd68f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code in ABAP: Liskov Substitution Principle (LSP)]]></title>
            <link>https://medium.com/@cihankaragoz/clean-code-in-abap-liskov-substitution-principle-lsp-56fbff563da9?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/56fbff563da9</guid>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[liskov-substitution]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 17:00:33 GMT</pubDate>
            <atom:updated>2025-02-04T17:00:33.934Z</atom:updated>
            <content:encoded><![CDATA[<p>In our journey to write clean and maintainable ABAP code, we’ve explored the <strong>Single Responsibility Principle (SRP)</strong> and the <strong>Open-Closed Principle (OCP)</strong>. Today, we’ll dive into the third principle of SOLID: the <strong>Liskov Substitution Principle (LSP)</strong>. We’ll use a classic example involving birds to illustrate how violating LSP can lead to issues and how to refactor the code to adhere to LSP.</p><h4>What is the Liskov Substitution Principle?</h4><p>The Liskov Substitution Principle states that:</p><blockquote><strong><em>“Objects of a superclass should be replaceable with objects of a subclass without affecting the correctness of the program.”</em></strong></blockquote><p>In simpler terms, if you have a base class and a derived class, you should be able to use the derived class wherever the base class is expected, without breaking the functionality of the program.</p><h4>Why is LSP Important in ABAP?</h4><p>In ABAP, we often use inheritance to create hierarchies of classes. For example, we might have a base class for <strong>Bird</strong> and derived classes for <strong>Sparrow</strong>, <strong>Penguin</strong>, and <strong>Eagle</strong>. LSP ensures that these derived classes behave in a way that is consistent with the base class. This is crucial for maintaining the integrity of the system and avoiding unexpected bugs.</p><h4>Example: Violating LSP with Birds</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*KEK3WrdVbX2zVelXNN_xWw.jpeg" /></figure><p>Let’s consider a scenario where we have a base class zcl_bird that represents a generic bird. It has a method fly because most birds can fly. However, when we create a subclass zcl_penguin for penguins, we encounter a problem: penguins cannot fly. This violates LSP because the subclass cannot substitute the base class without breaking the system.</p><pre>&quot; Base class for birds<br>CLASS zcl_bird DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS fly.<br>ENDCLASS.<br><br>CLASS zcl_bird IMPLEMENTATION.<br>  METHOD fly.<br>    WRITE: / &#39;Flying high in the sky!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>&quot; Subclass for penguins<br>CLASS zcl_penguin DEFINITION INHERITING FROM zcl_bird.<br>  PUBLIC SECTION.<br>    METHODS swim.<br>ENDCLASS.<br><br>CLASS zcl_penguin IMPLEMENTATION.<br>  METHOD swim.<br>    WRITE: / &#39;Swimming in the water!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.</pre><h4>Problem</h4><ul><li>The zcl_penguin class inherits the fly method from zcl_bird, even though penguins cannot fly.</li><li>If a program expects a zcl_bird object and receives a zcl_penguin object, calling fly on a penguin would be incorrect and break the system.</li></ul><h3>Refactored Solution: Adhering to LSP</h3><p>To adhere to LSP, we need to ensure that the subclass does not inherit methods it shouldn’t have. We can achieve this by <strong>redefining the class hierarchy</strong> and using <strong>interfaces</strong> to represent specific behaviors.</p><h4>Refactored ABAP Code</h4><pre>&quot; Interface for flying birds<br>INTERFACE zif_flying_bird.<br>  METHODS fly.<br>ENDINTERFACE.<br><br>&quot; Interface for swimming birds<br>INTERFACE zif_swimming_bird.<br>  METHODS swim.<br>ENDINTERFACE.<br><br>&quot; Base class for birds<br>CLASS zcl_bird DEFINITION.<br>  PUBLIC SECTION.<br>    METHODS eat.<br>ENDCLASS.<br><br>CLASS zcl_bird IMPLEMENTATION.<br>  METHOD eat.<br>    WRITE: / &#39;Eating food...&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>&quot; Class for flying birds (e.g., Sparrow)<br>CLASS zcl_sparrow DEFINITION INHERITING FROM zcl_bird.<br>  PUBLIC SECTION.<br>    INTERFACES zif_flying_bird.<br>ENDCLASS.<br><br>CLASS zcl_sparrow IMPLEMENTATION.<br>  METHOD zif_flying_bird~fly.<br>    WRITE: / &#39;Flying high in the sky!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>&quot; Class for swimming birds (e.g., Penguin)<br>CLASS zcl_penguin DEFINITION INHERITING FROM zcl_bird.<br>  PUBLIC SECTION.<br>    INTERFACES zif_swimming_bird.<br>ENDCLASS.<br><br>CLASS zcl_penguin IMPLEMENTATION.<br>  METHOD zif_swimming_bird~swim.<br>    WRITE: / &#39;Swimming in the water!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.<br><br>&quot; Class for another flying bird (e.g., Eagle)<br>CLASS zcl_eagle DEFINITION INHERITING FROM zcl_bird.<br>  PUBLIC SECTION.<br>    INTERFACES zif_flying_bird.<br>ENDCLASS.<br><br>CLASS zcl_eagle IMPLEMENTATION.<br>  METHOD zif_flying_bird~fly.<br>    WRITE: / &#39;Soaring above the mountains!&#39;.<br>  ENDMETHOD.<br>ENDCLASS.</pre><h4>Explanation</h4><p><strong>1.Base Class</strong>:</p><ul><li>The zcl_bird class represents the most generic behavior of birds, such as eat. It does not assume that all birds can fly.</li></ul><p><strong>2.Interfaces for Specific Behaviors</strong>:</p><ul><li>The zif_flying_bird interface defines the fly method for birds that can fly.</li><li>The zif_swimming_bird interface defines the swim method for birds that can swim.</li></ul><p><strong>3.Specialized Classes</strong>:</p><ul><li>The zcl_sparrow class implements the zif_flying_bird interface because sparrows can fly.</li><li>The zcl_penguin class implements the zif_swimming_bird interface because penguins can swim.</li><li>The zcl_eagle class implements the zif_flying_bird interface because eagles can fly.</li></ul><p><strong>4.No Inheritance of Inappropriate Methods</strong>:</p><ul><li>Penguins do not inherit the fly method, and sparrows/eagles do not inherit the swim method. This ensures that subclasses do not violate LSP.</li></ul><h4>Using the Refactored Classes</h4><pre>DATA: lo_sparrow TYPE REF TO zcl_sparrow,<br>      lo_penguin TYPE REF TO zcl_penguin,<br>      lo_eagle   TYPE REF TO zcl_eagle.<br><br>&quot; Create a sparrow<br>lo_sparrow = NEW zcl_sparrow( ).<br>lo_sparrow-&gt;eat( ). &quot; Output: Eating food...<br>lo_sparrow-&gt;zif_flying_bird~fly( ). &quot; Output: Flying high in the sky!<br><br>&quot; Create a penguin<br>lo_penguin = NEW zcl_penguin( ).<br>lo_penguin-&gt;eat( ). &quot; Output: Eating food...<br>lo_penguin-&gt;zif_swimming_bird~swim( ). &quot; Output: Swimming in the water!<br><br>&quot; Create an eagle<br>lo_eagle = NEW zcl_eagle( ).<br>lo_eagle-&gt;eat( ). &quot; Output: Eating food...<br>lo_eagle-&gt;zif_flying_bird~fly( ). &quot; Output: Soaring above the mountains!</pre><h4>Benefits of LSP in ABAP</h4><ul><li><strong>Consistency</strong>: Ensures that derived classes behave consistently with the base class.</li><li><strong>Predictability</strong>: Reduces the risk of unexpected behavior in the system.</li><li><strong>Maintainability</strong>: Makes the code easier to understand and maintain.</li></ul><h4>Conclusion</h4><p>The Liskov Substitution Principle is a key principle for designing robust and maintainable ABAP systems. By ensuring that derived classes can be used interchangeably with their base classes, we can build systems that are more reliable and easier to extend. In the next blog, we’ll explore the <strong>Interface Segregation Principle (ISP)</strong>, the fourth principle of SOLID.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56fbff563da9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code in ABAP: Open-Closed Principle (OCP)]]></title>
            <link>https://medium.com/@cihankaragoz/clean-code-in-abap-open-closed-principle-ocp-05734a28b930?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/05734a28b930</guid>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[open-closed-principle]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 15:40:23 GMT</pubDate>
            <atom:updated>2025-01-29T20:11:01.310Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of software development, writing clean and maintainable code is not just a best practice — it’s a necessity. As SAP developers, we often deal with complex business logic and ever-changing requirements. This is where the <strong>SOLID principles</strong> come into play. In my previous blog, I discussed the <strong>Single Responsibility Principle (SRP)</strong>. Today, we’ll dive into the second principle of SOLID: the <strong>Open-Closed Principle (OCP)</strong>.</p><h4>What is the Open-Closed Principle?</h4><p>The Open-Closed Principle states that:</p><blockquote><strong><em>“Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.”</em></strong></blockquote><p>In simpler terms, once a class or module is written and tested, it should not be modified to add new functionality. Instead, you should extend its behavior without changing its existing code. This principle helps us build systems that are flexible, scalable, and easy to maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4fCiIYc0DhRrInoNz9gLqg.jpeg" /></figure><h4>Why is OCP Important in ABAP?</h4><p>In ABAP, we often face situations where business requirements change frequently. For example:</p><ul><li>A new report needs to be added to an existing program.</li><li>A new condition or rule needs to be applied to a calculation.</li><li>A new output format needs to be supported.</li></ul><p>Without OCP, we might end up modifying existing code repeatedly, which can introduce bugs and make the system harder to maintain. By following OCP, we can design our code in a way that allows us to add new features without touching the existing, stable code.</p><h4>Example: Violating OCP in ABAP</h4><p>Let’s say we have a program that calculates discounts for different customer types. Initially, the program only handles two types of customers: <strong>Regular</strong> and <strong>Premium</strong>.</p><pre>METHOD calculate_discount.<br>  CASE customer_type.<br>    WHEN &#39;REGULAR&#39;.<br>      discount = amount * 0.1.<br>    WHEN &#39;PREMIUM&#39;.<br>      discount = amount * 0.2.<br>  ENDCASE.<br>ENDMETHOD.</pre><p>Now, suppose a new requirement comes in to support a third customer type: <strong>Gold</strong>. To implement this, we would need to modify the existing calculate_discount method:</p><pre>METHOD calculate_discount.<br>  CASE customer_type.<br>    WHEN &#39;REGULAR&#39;.<br>      discount = amount * 0.1.<br>    WHEN &#39;PREMIUM&#39;.<br>      discount = amount * 0.2.<br>    WHEN &#39;GOLD&#39;.<br>      discount = amount * 0.3.<br>  ENDCASE.<br>ENDMETHOD.</pre><p>This approach violates OCP because we are modifying the existing code to add new functionality. Every time a new customer type is introduced, we have to change this method, which increases the risk of introducing bugs.</p><h4>Refactoring to Follow OCP</h4><p>To adhere to OCP, we can use <strong>abstraction</strong> and <strong>inheritance</strong>. Here’s how:</p><ol><li><strong>Define an Abstract Class or Interface</strong>:<br>Create an abstract class or interface that defines the contract for calculating discounts.</li></ol><pre>CLASS zcl_discount_calculator DEFINITION ABSTRACT.<br>  PUBLIC SECTION.<br>    METHODS calculate_discount ABSTRACT<br>      IMPORTING amount TYPE f<br>      RETURNING VALUE(discount) TYPE f.<br>ENDCLASS.</pre><ol><li><strong>Create Concrete Classes for Each Customer Type</strong>:<br>Implement separate classes for each customer type.</li></ol><pre>CLASS zcl_regular_calculator DEFINITION INHERITING FROM zcl_discount_calculator.<br>  PUBLIC SECTION.<br>    METHODS calculate_discount REDEFINITION.<br>ENDCLASS.</pre><pre>CLASS zcl_regular_calculator IMPLEMENTATION.<br>  METHOD calculate_discount.<br>    discount = amount * 0.1.<br>  ENDMETHOD.<br>ENDCLASS.</pre><pre>CLASS zcl_premium_calculator DEFINITION INHERITING FROM zcl_discount_calculator.<br>  PUBLIC SECTION.<br>    METHODS calculate_discount REDEFINITION.<br>ENDCLASS.</pre><pre>CLASS zcl_premium_calculator IMPLEMENTATION.<br>  METHOD calculate_discount.<br>    discount = amount * 0.2.<br>  ENDMETHOD.<br>ENDCLASS.</pre><ol><li><strong>Extend Without Modifying Existing Code</strong>:<br>When a new customer type is introduced, simply create a new class without modifying the existing ones.</li></ol><pre>CLASS zcl_gold_calculator DEFINITION INHERITING FROM zcl_discount_calculator.<br>  PUBLIC SECTION.<br>    METHODS calculate_discount REDEFINITION.<br>ENDCLASS.</pre><pre>CLASS zcl_gold_calculator IMPLEMENTATION.<br>  METHOD calculate_discount.<br>    discount = amount * 0.3.<br>  ENDMETHOD.<br>ENDCLASS.</pre><ol><li><strong>Use Polymorphism</strong>:<br>Use the abstract class or interface to call the appropriate implementation.</li></ol><pre>DATA(lo_calculator) = COND #(<br>  WHEN customer_type = &#39;REGULAR&#39; THEN NEW zcl_regular_calculator( )<br>  WHEN customer_type = &#39;PREMIUM&#39; THEN NEW zcl_premium_calculator( )<br>  WHEN customer_type = &#39;GOLD&#39; THEN NEW zcl_gold_calculator( )<br>).</pre><pre>discount = lo_calculator-&gt;calculate_discount( amount ).</pre><h4>Benefits of OCP in ABAP</h4><ul><li><strong>Flexibility</strong>: New functionality can be added without changing existing code.</li><li><strong>Maintainability</strong>: Reduces the risk of introducing bugs in stable code.</li><li><strong>Scalability</strong>: Makes it easier to extend the system as requirements evolve.</li></ul><h4>Conclusion</h4><p>The Open-Closed Principle is a powerful tool for writing clean and maintainable ABAP code. By designing our systems to be open for extension but closed for modification, we can build software that is robust, scalable, and easy to maintain. In the next blog, we’ll explore the <strong>Liskov Substitution Principle (LSP)</strong>, the third principle of SOLID.</p><p><em>**ABAP codes are expressed in the simplest way to explain the open close principle. The caller program has to be modified when a new customer arrives. This can be solved with a solution such as factory class for object creation, but since the main focus is on abstract classes, new inheriting classes and interfaces not caller program, such solution has not been added so that it is not difficult to understand this issue.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05734a28b930" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code in ABAP: Single Responsibility Principle (SRP)]]></title>
            <link>https://medium.com/@cihankaragoz/clean-code-in-abap-single-responsibility-principle-srp-d6cda1d7aa0f?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6cda1d7aa0f</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[single-responsibility]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 17:03:28 GMT</pubDate>
            <atom:updated>2025-01-23T17:03:28.639Z</atom:updated>
            <content:encoded><![CDATA[<p>Clean code is like a well-organized kitchen; you can find everything easily and work efficiently. I have started a blog series on the SOLID principles and in this blog I’m focusing on the <strong>Single Responsibility Principle (SRP)</strong>. This principle is the foundation of clean code. Let’s keep it simple and clear.</p><h3>What is the Single Responsibility Principle?</h3><p>As ABAP consultants, we often find ourselves in a rush to deliver functionality quickly, leading to a common violation of the Single Responsibility Principle (SRP), the cornerstone of the SOLID principles. We often see large methods or classes that try to do everything at once — handling data, business logic, and even the user interface — all in one place. This “do-it-all” approach may seem efficient initially but becomes a nightmare to maintain, debug, and extend. In the evolving SAP ecosystem, where clean, modular, and reusable code is more critical than ever, adhering to SRP is not just a best practice — it’s a necessity.</p><p>The Single Responsibility Principle states that <strong>a class should have only one reason to change</strong>. In other words, a class (or a function or a method) should do one thing and one thing only.</p><p>To make it easy to understand, think of a person trying to be a <strong>police officer</strong>, a <strong>doctor</strong>, and a <strong>cook</strong> all at once. It’s impossible to excel in all roles simultaneously, and responsibilities will become chaotic. Similarly, if you put multiple responsibilities into one class or method, your code becomes hard to maintain, test, and extend.</p><h3>Don’t Be a “Jack of All Trades”</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*W2OtvVxkSaCBSJttniPQVg.jpeg" /></figure><p>Imagine a person wearing three hats:</p><ul><li>A <strong>police cap</strong> for enforcing laws,</li><li>A <strong>stethoscope</strong> for treating patients, and</li><li>A <strong>chef’s hat</strong> for cooking meals.</li></ul><p>This person is overwhelmed and ineffective. The same goes for your code if it tries to handle too many tasks at once.</p><h3>Why is SRP Important?</h3><ol><li><strong>Readability</strong>: Code becomes easier to understand when it does one thing.</li><li><strong>Maintainability</strong>: Changes in one responsibility won’t affect others.</li><li><strong>Testability</strong>: Smaller classes/functions are easier to test.</li><li><strong>Reusability</strong>: A class focused on one responsibility is easier to reuse.</li></ol><h3>ABAP Example: A Before and After Look</h3><h3>Before SRP</h3><p>Here’s an easy and clear example of a method that violates SRP. It handles both <strong>employee data retrieval</strong> and <strong>salary calculations</strong>:</p><pre>METHOD get_employee_data.<br>  DATA: employee_data TYPE TABLE OF ty_employee_data,<br>        salary        TYPE p DECIMALS 2.<br><br>  &quot; Fetch employee data from database<br>  SELECT * FROM zemployee WHERE employee_id = employee_id<br>    INTO CORRESPONDING FIELDS OF TABLE employee_data.<br><br>  &quot; Calculate salary<br>  salary = hours_worked * 50.<br><br>  &quot; Return results<br><br>ENDMETHOD.</pre><p>This method is doing two things:</p><ol><li>Retrieving employee data.</li><li>Calculating salaries.</li></ol><p>If there’s a change in how salaries are calculated, you’ll need to modify this method, potentially affecting the data retrieval logic as well.</p><h3>After SRP</h3><p>Let’s refactor this into two separate methods, each with a single responsibility:</p><pre>METHOD get_employee.<br>  &quot; Fetch employee data from database<br>  SELECT * FROM zemployee WHERE employee_id = employee_id<br>    INTO CORRESPONDING FIELDS OF TABLE employee_data.<br>ENDMETHOD.</pre><pre>METHOD calculate_salary.<br>  &quot; Simple salary calculation<br>  salary = hours_worked * 50.<br>ENDMETHOD.</pre><p>Now, <strong>get_employee</strong> focuses on data retrieval, and <strong>calculate_salary</strong> handles salary calculations. Each method has one responsibility, making the code easier to maintain and test.</p><h3>Conclusion</h3><p>By following the Single Responsibility Principle, you can:</p><ul><li>Write cleaner, more maintainable code.</li><li>Reduce the risk of unintended side effects.</li><li>Make your code easier to test and extend.</li></ul><p>See you in the next post about<strong> Open/Closed Principle.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6cda1d7aa0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ever-Changing SAP World and the Timeless Value of Clean Code]]></title>
            <link>https://medium.com/@cihankaragoz/the-ever-changing-sap-world-and-the-timeless-value-of-clean-code-51707357dbe5?source=rss-7f450fd0909b------2</link>
            <guid isPermaLink="false">https://medium.com/p/51707357dbe5</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[sap]]></category>
            <dc:creator><![CDATA[Cihan Karagoz]]></dc:creator>
            <pubDate>Wed, 15 Jan 2025 17:33:47 GMT</pubDate>
            <atom:updated>2025-01-15T17:33:47.246Z</atom:updated>
            <content:encoded><![CDATA[<p>In the SAP world, change is the only constant. With the rise of SAP BTP (Business Technology Platform) and a wave of new technologies transforming how we work, developers must adapt quickly to stay relevant. As tools and platforms evolve, one thing remains timeless: <strong>the importance of clean code</strong>.</p><p>Clean code is not just a best practice; it is the foundation for scalability, maintainability, and collaboration in any development project. Whether you are working with traditional ABAP systems or exploring the latest innovations in S/4HANA, clean code principles ensure that your work remains robust and future-proof.</p><h3>Why Start with Clean Code?</h3><p>As developers, we often focus on delivering features and meeting deadlines. However, writing clean code should be our starting point, not an afterthought. Here’s why:</p><ol><li><strong>Sustainability</strong>: Clean code is easier to maintain and adapt when requirements change — which they always do.</li><li><strong>Collaboration</strong>: Your colleagues will thank you for writing code that’s easy to understand and extend.</li><li><strong>Bug Reduction</strong>: Cleaner code often leads to fewer bugs, saving time in the long run.</li><li><strong>Performance</strong>: While clean code isn’t about speed, structured logic often leads to more efficient solutions.</li></ol><p>Clean code is not just about aesthetics; it’s about writing software that works well today and can grow with the challenges of tomorrow. It helps you and your team navigate complexity without losing sight of your goals.</p><h3>What’s Coming Next?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkuPmvkbnPoUaSWDMYCZPg.png" /></figure><p>In this blog series, I will dive into the <strong>SOLID principles</strong>, a set of guidelines for writing clean, maintainable code. These principles are:</p><ol><li><strong>Single Responsibility Principle (SRP)</strong>: Each class should have one, and only one, reason to change.</li><li><strong>Open/Closed Principle (OCP)</strong>: Classes should be open for extension but closed for modification.</li><li><strong>Liskov Substitution Principle (LSP)</strong>: Objects of a superclass should be replaceable with objects of a subclass without affecting the application.</li><li><strong>Interface Segregation Principle (ISP)</strong>: A class should not be forced to implement interfaces it doesn’t use.</li><li><strong>Dependency Inversion Principle (DIP)</strong>: High-level modules should not depend on low-level modules; both should depend on abstractions.</li></ol><p>Each principle helps address a specific aspect of software design, creating a codebase that is easier to understand, test, and maintain.</p><p>While the examples will focus on ABAP, the principles are universal and serve as a starting point for all developers.</p><p>As a bonus, I will also discuss the <strong>Single Level of Abstraction</strong> principle — an invaluable concept for structuring your methods effectively.</p><h3>The Key to Thriving in a Rapidly Changing Landscape</h3><p>SAP technology is evolving at a rapid pace, and the demands on developers are growing. By focusing on clean code, you are not just writing better software; you are investing in your ability to adapt and thrive in a world of constant change.</p><p>Clean code is not a luxury or an advanced skill — it is the foundation of professional software development. It ensures that your work remains relevant, understandable, and ready for whatever comes next.</p><p>Remember, clean code is where every developer’s journey should begin.</p><p>See you next post about<strong> SRP.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51707357dbe5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>