Open Yrfo opened 3 years ago
There is a book Design Patterns in ABAP Objects by Kerem Koseoglu from 2016 about specifically this topic. It describes how to implement the common standard design patterns in ABAP.
Thanks @HrFlorianHoffmann! I didn't know about the book. Need to have a look.
But the question, I think, is still open. There is also Clean ABAP book and we have main information collected here in git, which is being discussed and adjusted by community. Can the same approach be applied to Design Patterns?
Not that it cannot be done but I would argue that Design Patterns are much more language-agnostic. That's why they're usually described using UML Class Diagrams. I wonder if adding them here will bring any real value.
Tbh, I find that book code rather confusing. Its only accomplishment, which is already a great thing, was to introduce Design Patterns to most ABAP programmers still not familiar with them. But whenever I need to read about Design Pattern I always prefer to look at more agnostic books like the great Head First Design Patterns or Design Patterns: Elements of Reusable Object-Oriented Software. Even Wikipedia has great pages on most - if not all - common patterns.
Using them in ABAP is just matter of converting the UML into ABAP syntax.
I first dismissed the idea about Object Pattern guide as it's a huge topic all on it's own. I have an older book by another author https://www.sap-press.com/design-patterns-in-object-oriented-abap_2018/ which I found really good. You may still find it on Amazon.
But... the more I think about it, the more I am coming round to the idea there may be some best practices on how to implement the patterns themselves. Consider the humble factory pattern. We have Factory Method vs. Factory class vs. Abstract factory. Then there's the question of should ABAP factories be instances or static?
zcl_widget_factory=>get_instance( )->get_widget( ).
vs.
zcl_widget_factory=>get_widget( ).
Most people will write static methods, but the longer instance version can easily be mocked for unit tests. So perhaps there is room for an OO Patterns section?
Hello,
Is it possible to define some common view on better way how certain design patterns should be implemented in ABAP? I saw time to time some blogs on that topic, some very useful some maybe less. But then they always lost somewhere.
I would like to have here, kind of single source of truth (if I can name it like this :smile:) collected information from experts on that topic.
As Robert C. Martin's Clean Code became source for clean ABAP. Maybe 'Design Patterns: Elements of Reusable Object-Oriented Software' can be source for design patterns for ABAP here.