[null, {"document_url": "http://zevolving.com/2011/10/abap-objects-design-patterns-factory-method/", "unformatted_src": "http://1.bp.blogspot.com/-2odI30dMMow/TqVVWtnvhqI/AAAAAAAAAGY/zpMiVXJTNZA/s400/factory_uml.png", "src": "http://1.bp.blogspot.com/-2odI30dMMow/TqVVWtnvhqI/AAAAAAAAAGY/zpMiVXJTNZA/s400/factory_uml.png", "formatted_filename": "factory uml", "rendered_width": 400, "rendered_height": 208}, null, null, null]


ABAP Objects Design Patterns – Factory Method

By Naimesh Patel | October 24, 2011 | ABAP Objects, OO Design Patterns | 41,838 | 3

Factory Method design pattern could be most used design pattern in the modern world application. Factory method design pattern hides all the complexity of the instantiating an object from the consumer.


This DP provides an unique interface for object instantiation. This interface creates an object but let subclasses decide which class to instantiate.

Design time consideration:


For demo purpose, we will use this UML. We have OPHANDLER which contains the FACTORY method. This method is Public and STATIC. This super class has another method called PROCESS_OUTPUT( ). We’ll also inherit some subclasses from the class OPHANDLER: OPHANDLER_ZABC to process ZABC output and OPHANDLER_ZXYZ to process ZXYZ output.

The FACTORY method has one importing parameter: Output Type and one Returning parameter, the object. Based on the requested output type, we’ll instantiate the object. For demo, I kept the implementation of FACTORY method simple: just calling CREATE OBJECT with TYPE of subclass.

Code Lines:

Lets see the code lines on how to implement this:

SDN wiki – Factory Method Design Pattern


ABAP Objects Factory OO Design patterns



 
I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :




Comments on this Post are now closed. If you have something important to share, you can always contact me.

ABAP Objects Design Patterns - Decorator


