0% found this document useful (0 votes)
376 views4 pages

ABAP Object Oriented Design Pattern Adapter (Wrapper)

The document discusses the Adapter design pattern in ABAP Object Oriented programming. The Adapter pattern allows classes with incompatible interfaces to work together by wrapping one class with a "wrapper" class that implements the expected interface. An example is provided where a class that generates tree output is wrapped with an adapter class that implements the interface expected by the client, allowing the client to access the tree output generation capabilities indirectly.

Uploaded by

sudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
376 views4 pages

ABAP Object Oriented Design Pattern Adapter (Wrapper)

The document discusses the Adapter design pattern in ABAP Object Oriented programming. The Adapter pattern allows classes with incompatible interfaces to work together by wrapping one class with a "wrapper" class that implements the expected interface. An example is provided where a class that generates tree output is wrapped with an adapter class that implements the interface expected by the client, allowing the client to access the tree output generation capabilities indirectly.

Uploaded by

sudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

8/31/2016 ABAPObjectOrientedDesignPatternAdapter(Wrapper)

ZEVOLVING e.g.ABAPObjects

> Home > ABAP Objects > OO Design Patterns ABAP Objects Design Patterns Adapter

ABAP Objects Design Patterns Adapter


By Naimesh Patel | January 16, 2012 | ABAP Objects, OO Design Patterns | 5,529 | 0

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.

UML for Adapter


HereistheUMLforourdemo:

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.

Adapter Design Patter in OO ABAP



REPORTZNP_DP_ADAPTER.
*
INTERFACElif_output.
METHODS:generate_output.
ENDINTERFACE."lif_output
*
CLASSsimple_opDEFINITION.
PUBLICSECTION.
INTERFACES:lif_output.
ENDCLASS."simple_opDEFINITION

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().

Design Time Considerations


WeshouldconsiderthiswhileimplementingtheAdapter.

CreateaclassimplmentingthesameinterfacewhichisrequriedbyClient
InstantiatetheObjectwhoseInterfaceisincompitible
Calltherespectivemethodstoperformanactionwithintheimplementedmethodsofinterface.

Letmeknow,ifyouhaveimplementedthisdesignPatternandrealizeditsbenefits.

Check out all Design Patterns


YoumayalsowanttoexploreallotherDesignPatternsinOOABAP.

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

Naimesh Patel {270 articles}


I'mSAPABAPConsultantformorethanadecade.IliketoexperimentwithABAPespeciallyOO.IhavebeenSDNTopContributor.
Follow:

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

You might also like