11-29-2020 6:12 PM
What is Factory Design Pattern ? What is the real time example of factory design pattern in terms of SAP?
11-29-2020 7:25 PM
Hi varun1995
Here's about the pattern: https://en.wikipedia.org/wiki/Factory_method_pattern
Here's an example for ABAP: https://blogs.sap.com/2012/02/20/factory-pattern-in-abap-oo/
The example is complex, with configuration based on DB table, but it can also be as simple as
METHOD create_instance.
IF iv_value = 'A'.
CREATE OBJECT ro_instance TYPE lcl_a.
ELSE.
CREATE OBJECT ro_instance TYPE lcl_default.
ENDIF.
ENDMETHOD.
Kind regards,
Mateusz
11-29-2020 7:25 PM
Hi varun1995
Here's about the pattern: https://en.wikipedia.org/wiki/Factory_method_pattern
Here's an example for ABAP: https://blogs.sap.com/2012/02/20/factory-pattern-in-abap-oo/
The example is complex, with configuration based on DB table, but it can also be as simple as
METHOD create_instance.
IF iv_value = 'A'.
CREATE OBJECT ro_instance TYPE lcl_a.
ELSE.
CREATE OBJECT ro_instance TYPE lcl_default.
ENDIF.
ENDMETHOD.
Kind regards,
Mateusz
11-30-2020 3:13 AM
11-30-2020 7:15 AM
Hello varun1995,
The factory method is most used for creating objects without any leverage to its instantiation technique. Interfaces and encapsulation concepts of OOABAP plays a vital role here.
You can follow the blog below which discusses the method in detail.
Regards!