SOLID ABAP
SOLID ABAP
Rotting Design
Symptoms:
Rigidity Fragility
the tendency of the software to be difficult to the tendency of the software to break in many places
change every time it is changed
Immobility Viscosity
the inability to reuse the software from other it is easy to do the wrong thing (the hack) but hard to
projects do the right one (preserve the design)
Design Principles and Design Patterns (2000) by Robert C. Martin (Uncle Bob)
EPAM Proprietary & Confidential. 4
WHAT IS PROBLEM?
Incomplete
requirements
Changing requirements
Dependencies
Fast-changing
world
Rotting design
Design Principles and Design Patterns (2000) by Robert C. Martin (Uncle Bob)
EPAM Proprietary & Confidential. 5
WHAT IS PROBLEM?
Design Patterns
Design Principles
Creational
Object-Oriented Concepts
Fundamental
Structural
Design Principles
Open/Closed Principle
Favor composition
Liskov Substitution Principle
Program to interface
Interface Segregation Principle
Loose coupling Dependency Inversion Principle
Design Principles and Design Patterns (2000) by Robert C. Martin (Uncle Bob)
EPAM Proprietary & Confidential. 8
DESIGN PRINCIPLES
Fundamental Principles
METHOD main.
IF order_type = 'Cash’
DATA(order) = NEW zcash_sale_order( ).
ELSEIF order_type = 'Third_party’
order = NEW zthird_party_order( ). Code that is prone to changes.
ELSEIF order_type = 'Rush’
order = NEW zrush_order( ).
ENDIF.
order.prepare( ).
order.run_schedule_lines( ).
order.run_pricing( ).
ENDMETHOD.
PUBLIC SECTION.
CLASS-METHODS create_order METHOD main.
IMPORTING order_type TYPE string DATA(order) = z_order_factory=>create_order( order_type ).
RETURNING VALUE(order) TYPE REF TO z_sales_order.
PROTECTED SECTION.
order.prepare( ).
PRIVATE SECTION. order.run_schedule_lines( ).
ENDCLASS. order.run_pricing( ).
ENDMETHOD.
CLASS z_order_factory IMPLEMENTATION.
METHOD createorder.
IF order_type = 'Cash’
order = NEW zcash_sale_order( ).
ELSEIF order_type = 'Third_party’
order = NEW zthird_party_order( ).
ELSEIF order_type = 'Rush’
order = NEW zrush_order( ).
ENDIF.
ENDMETHOD.
ENDCLASS.
Fundamental Principles
As the requirements
increase, inheritance can
expand both horizontally
and vertically, which can
potentially lead to increased
code rigidity.
Fundamental Principles
Loose Coupling
Components should be built independently with
minimal dependencies on each other to ensure
flexibility and maintainability, as well as decrease
the risk of potential ripple effects during
modifications.
Loose Coupling
Tightly Coupled
The order depends on the
concrete implementation of the
Printer class.
Loose Coupling
Loose Coupling
The order does not know
concrete implementations, it
works with the Output interface.
Fundamental Principles
Program to Interface,
not Implementation
Recommendation to code against abstract
interfaces or base classes instead of specific
classes or implementations, to maximize
flexibility and ensure interchangeability of
objects
SOLID Principles
Single Responsibility
Principle
The class should have just one specific
responsibility or reason to change, ensuring
simplicity and improved maintainability in
software design.
PUBLIC SECTION.
METHODS prepare.
ENDCLASS.
METHOD prepare.
authenticator->is_prepare_allowed( ).
"do document preparation
ENDMETHOD.
ENDCLASS.
SOLID Principles
Open/Closed Principle
The class should be open for extension but
closed for modification, thus promoting code
extensibility without risking the existing
functionality
Open/Closed Principle
SOLID Principles
Liskov Substitution
Principle
A subtype must be substitutable for its base type
without altering the correctness of the program
while ensuring consistency.
METHOD if_oo_adt_classrun~main.
out->write(
EXPORTING
data = NEW lcl_material( )->save( )
name = 'Material’
).
ENDMETHOD.
Since both classes yield
different results, it
indicates that they are
METHOD if_oo_adt_classrun~main.
not substitutable.
out->write(
EXPORTING
data = NEW lcl_haz_material( )->save( )
name = ‘HazMaterial’
).
ENDMETHOD.
SOLID Principles
Interface Segregation
Principle
Clients should depend on client-specific
interfaces with only the set of operations they
require.
INTERFACE lif_material_master.
Even for materials that
METHODS: create, don't need certain
read,
update, methods, they would
delete, still be forced to
calculate_weight,
depreciate. implement them,
ENDINTERFACE. potentially providing
CLASS lcl_material DEFINITION. consumers with
PUBLIC SECTION.
INTERFACES: lif_material_master.
unnecessary features
ENDCLASS. or functionality.
INTERFACE lif_material_master_calculate.
The operations are split
METHODS: calculate_weight. into more focused/cohesive
ENDINTERFACE.
interfaces. Class does not
INTERFACE lif_material_master_depreciate.
METHODS: depreciate. depend on methods it does
ENDINTERFACE.
not use.
CLASS lcl_material DEFINITION.
PUBLIC SECTION.
INTERFACES: lif_material_master_crud.
ENDCLASS.
SOLID Principles
Dependency Inversion
Principle
High-level modules should not depend on low-
level modules; instead, both should depend on
abstractions.
Technical Debt
The implied cost of future reworking is required when choosing an easy but limited solution instead of a better
approach that can take more time /Wikipedia/
Actual CoC
Cost Of Change (CoC)
Technical
Debt
Ideal CoC
Time
15X
7X
3X
1X
Development
Requirments Design / Coding Testing Deployment cycle
Architecture
The Economic Impacts of Inadequate Infrastructure for Software Testing, National Institute of Standards and Technology, 2022
15X
6.5X
1X
Development
Design Implemantation Testing Maintenance cycle
IBM System Science Institute Relative Cost of Fixing Defects
EPAM Proprietary & Confidential. 42
”Any fool can write code that a
computer can understand. Good
programmers write code that
humans can understand.”
Martin Fowler