Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
shreevathsa_s
Explorer
0 Kudos

Factory pattern is one of the creational design patterns in object oriented design. This blog explains one of the approaches on how this pattern can be extended and implemented in ABAP Object Oriented Programming (OO).

In factory pattern, different implementations of an interface are instantiated based on a configuration.  Now, let us take a case where there are multiple implementations for multiple interfaces. The factory class would now have to choose specific implementation for a specific interface.

You can find an example class diagram in the file "factory_pattern.png".

E type configuration table

Interface_Name

Class_Name

IF_GENERIC

CL_SPECIFIC

IF_GENERIC_1

CL_SPECIFIC_1

C type configuration table

Interface_Name

Class_Name

IF_GENERIC_1

ZCL_SPECIFIC_1

 
 

Algorithm within the class “CL_CLASS_FACTORY”

  1. Based on the interface, read customer’s configuration table to get the class name.
  2. If class name is not maintained in (1), read the configuration from SAP delivered configuration table to get class name from interface name.

For the above example, for interface IF_GENERIC, class CL_GENERIC is picked up from the configuration table whereas for the interface IF_GENERIC_1, class CL_GENERIC_1 is picked up from the configuration.

1 Comment