ABAP Object Oriented Design Pattern Adapter (Wrapper)
ABAP Object Oriented Design Pattern Adapter (Wrapper)
ZEVOLVING e.g.ABAPObjects
> Home > ABAP Objects > OO Design Patterns ABAP Objects Design Patterns Adapter
Adapterdesignpattern,anotherwidelyuseddesignpatternintherealworldaswellastheObjectOrientedProgramminglanguage.StandardSAPdevelopments
buildinOOABAPalsousesAdapterDPalot.
What is Adapter
AdapterconvertstheobjectswhichareincompatibleduetothedifferenceintheInterface.ByimplementingAdapter,wecanallowclassestoworktogether,
whichcantworkwithoutimplementingtheAdapter.
Sometimes,wehaveaclientwhoexpectstheobjectwithcertaininterfaceonly.Wedohaveanotherobjectwhichcansatisfytherequirementbutbothobjects
interfacesaredifferent.So,wecantdirectlycalltheexistingobjectwithusingthesameinterface.So,weneedtocreateakindofwrapperwhichcantranslate
theobjectsinterfacetotheinterfacewhichisacceptedbyclientorotherobject.
Soundsfamiliar?yes,weusethistypeofwrapperinlotofsituationbothinrealworldandinProgramming.Inrealworld,weuselikeMiniSDcardreaderwith
USB,sowecanreadthedatafromit.InABAP,stdSAPusesthisinmostoftheBAPIFMs.
WehaveasimpleoutputclassimplementingtheLIF_OUTPUT.ClientisusingtheinterfaceLIF_OUTPUTtointeractwithoutputobject.LetsseehowAdapteris
achieved:
LIF_OUTPUTClientaccpetstoonlyworkwiththeobjectswiththisinterfaceonly.So,allourobjectswhichshouldinteractwithclientmusthavethis
interface.ThiscomponentiscalledasTarget.
TREE_OUTPUTThisistheobjectwhichdoesnthavethesameInterface.ButthisobjectsatisfiesallourrequirementtogeneratetheTREEoutput.This
componentisreferredasAdaptee.
NEW_COMPLEX_OPThisisanewobjectwhoactasWrapperonTREE_OUTPUTwiththeinterfaceofLIF_OUTPUT.So,clientcanseamlessly
generatethecomplexoutput(TREE)withusingthesameinterface.ThisiscalledasAdapter.
SALVmodelusesAdaptertomaptheattributesfromSALVcompatibleinterfacetoClassicalALVorALVGridattributes.
Code Lines
LetscheckoutthecodelinesonhowtoachieveAdapterinOOABAP.
http://zevolving.com/2012/01/abapobjectsdesignpatterns%E2%80%93adapter/ 1/4
8/31/2016 ABAPObjectOrientedDesignPatternAdapter(Wrapper)
*
CLASSsimple_opIMPLEMENTATION.
METHODlif_output~generate_output.
WRITE:/'SimpleOutputjustusingWRITE'.
ENDMETHOD."lif_output~generate_output
ENDCLASS."simple_opIMPLEMENTATION
*
CLASStree_outputDEFINITION.
PUBLICSECTION.
METHODS:generate_tree.
ENDCLASS."tree_outputDEFINITION
*
CLASStree_outputIMPLEMENTATION.
METHODgenerate_tree.
WRITE:/'CreatingTree...usingCL_GUI_ALV_TREE'.
ENDMETHOD."generate_tree
ENDCLASS."tree_outputIMPLEMENTATION
*
CLASSnew_complex_opDEFINITION.
PUBLICSECTION.
INTERFACES:lif_output.
ENDCLASS."new_complex_opDEFINITION
*
CLASSnew_complex_opIMPLEMENTATION.
METHODlif_output~generate_output.
DATA:o_tree_opTYPEREFTOtree_output.
CREATEOBJECTo_tree_op.
o_tree_op>generate_tree().
ENDMETHOD."lif_output~generate_output
ENDCLASS."new_complex_opIMPLEMENTATION
*
STARTOFSELECTION.
DATA:o_opTYPEREFTOlif_output.
CREATEOBJECTo_opTYPEsimple_op.
o_op>generate_output().
*usingthesame"simple"Interfacetoperformthe"complex",
*SinceClientonlywantstouseSimpleinterface..
CREATEOBJECTo_opTYPEnew_complex_op.
o_op>generate_output().
CreateaclassimplmentingthesameinterfacewhichisrequriedbyClient
InstantiatetheObjectwhoseInterfaceisincompitible
Calltherespectivemethodstoperformanactionwithintheimplementedmethodsofinterface.
Letmeknow,ifyouhaveimplementedthisdesignPatternandrealizeditsbenefits.
ABAPObjectDesignPatternsSingleton
ABAPObjectsDesignPatternsModelViewController(MVC)Part1
ABAPObjectsDesignPatternsModelViewController(MVC)Part2
ABAPObjectsDesignPatternsModelViewController(MVC)Part3
ABAPObjectsDesignPatternsDecorator
ABAPObjectsDesignPatternsFactoryMethod
ABAPObjectsDesignPatternsObserver
CaseStudy:ObserverDesignPatternUsage
ABAPObjectsDesignPatternsAbstractFactory
OODesignPatternDecoratorWhydoweneedtousehelpervariable?
ABAPObjectsDesignPatternsFacade
ABAPObjectsDesignPatternsAdapter
ABAPObjectsDesignPatternsComposite
ABAPObjectsDesignPatternsIterator
IteratorDesignPatterntoaccessLinkedListinABAPObjects
ABAPObjectsDesignPatternsProxy
ABAPObjectsDesignPatternsPrototype
ABAPObjectsDesignPatternsSingletonFactory
ABAPObjectOrientedApproachforReportsInitialDesign
ABAPObjectOrientedApproachforReportsRedesign
ABAPObjectsDesignPatternsBuilder
ABAPObjectsDesignPatternsSingletonUsage
ABAPMVCModelViewControllerDiscussion
ObjectOrientedApproachforReportswithmultipleDatasource
OOABAPSelectionObjectwithDirectAccess
OOABAPSelectionCriteriaObjectusingRS_REFRESH_FROM_SELECTOPTIONS
ABAPFactoryMethodUsingSWITCH
http://zevolving.com/2012/01/abapobjectsdesignpatterns%E2%80%93adapter/ 2/4
8/31/2016 ABAPObjectOrientedDesignPatternAdapter(Wrapper)
Tags
OOABAP OODesignpatterns
Exploreallofhis270articles.
TOP
Comments on this Post are now closed. If you have something important to share, you can always contact me.
Subscribe
Keep in touch. We would do great working together.
1400
SubscribetoEmail
Follow@zevolving
your email
ABAP Help
Follow +1
+ 1,511
Current Poll
DoyoulikeQualityAssuranceofyourBuild/Design?
YES. I live for it!
I don't mind
NO. I hate it
Vote
View Results
Search
SearchinZevolving
zevolving.comisfoundedbyandmaintainedbyNaimeshPatel.YoucanhelpbysubmittingyourarticlesviaWriteaPost.ThesiteisbuiltonWordpress.
HappyDesigning!
http://zevolving.com/2012/01/abapobjectsdesignpatterns%E2%80%93adapter/ 3/4
8/31/2016 ABAPObjectOrientedDesignPatternAdapter(Wrapper)
About Subscribe Advertise Licence
Allproductnamesaretrademarksoftheirrespectivecompanies.zevolving.comisnotaffiliatedwithSAPAG.
TOP
http://zevolving.com/2012/01/abapobjectsdesignpatterns%E2%80%93adapter/ 4/4