ABAP objects design patterns
hi all,
can any one send me the Design patterns used for ABAP objects programming in ABAP. eg mvc and sample code which uses the design patterns
cheers
senthil
Of course that program is not an object design pattern
(Its just a little ABAP Objects syntax demo that I wrote years ago
I don't know about a list of OO design patterns implemented in ABAP Objects.
A very simple one, a Singleton might look like this:
<b>* cl_singleton: Eager Variant
CLASS cl_singleton DEFINITION FINAL
CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS: class_constructor,
get_singleton RETURNING VALUE(singleton)
TYPE REF TO cl_singleton.
PRIVATE SECTION.
CLASS-DATA singleton TYPE REF TO cl_singleton.
ENDCLASS.
CLASS cl_singleton IMPLEMENTATION.
METHOD class_constructor.
CREATE OBJECT singleton.
ENDMETHOD.
METHOD get_singleton.
singleton = cl_singleton=>singleton.
ENDMETHOD.
ENDCLASS.
cl_singleton: Lazy Variant
CLASS cl_singleton DEFINITION FINAL
CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS get_singleton RETURNING VALUE(singleton)
TYPE REF TO cl_singleton.
PRIVATE SECTION.
CLASS-DATA singleton TYPE REF TO cl_singleton.
ENDCLASS.
CLASS cl_singleton IMPLEMENTATION.
METHOD get_singleton.
IF cl_singleton=>singleton IS INITIAL.
CREATE OBJECT cl_singleton=>singleton.
ENDIF.
singleton = cl_singleton=>singleton.
ENDMETHOD.
ENDCLASS.</b>
Similar Messages
-
ABAP Objects Design/Organization Issues
Hi,
I'm trying to design and implement reusable components using ABAP Objects. I'm familliar with OO concepts and have developed a few applications using C++ and Java.
I'm trying to organize my classes into separate source files (include program in ABAP).
ie.
<b>include program a</b>
CLASS a DEFINITION.
ENDCLASS.
<b>include program b</b>
INCLUDE a.
CLASS b DEFINITION.
data x TYPE REF TO a.
ENDCLASS.
Lets say I want to write a report that uses both objects a and b. That means I have to include both programs. but since program b includes program a. including both programs a and b in my report would produce redeclarations of class a.
<b>executable program c</b>
REPORT c.
INCLUDE a.
INCLUDE b. " error: redeclaration of class a
DATA: x TYPE REF TO a.
y TYPE REF TO b.
This bothers me. Although it would be possible to <b>just include program b</b>, it would be a bit awkward since, i dont care if class a was used in the implementation of class b. Implementation should be abstracted from the user. Besides, everything should be explicit.
Is there a way to organize things as such? Would importing these classes globally would solve the problem.
Thanks.Emir,
The way we do OO Programming in ABAP and other languages differ.
In your case, it might be a better option to create these classes as global classes, so that you will not have this issue. You can SE24 to do the same.
Regards,
Ravi -
Data Transfer Objects Design Pattern
Hi All,
Could anyone tell me more about this DTO design pattern, as such when one should prefer it.
Second is this pattern transaction safe or one would have to implement the same manually. Any updates would prove benefecial to me.Hi
I do not understand what you mean.
A dto is just an object which you populate in one layer and use in another layer.
you do not need any jndi look for DTO , instead you lookup for ejbs , datasources ,....
for example you lookup for some CMP , search and find some CMPs , populate DTO with those CMP and send the DTO to front layer.
if it is not the answer , can you explain more about your requirements(S) -
i have to develop a web base applecation which is database indepandent, to achive this functionlity i have to use DAO design pattern.
can some one explane me more about this............................Data Access Object:
Java BluePrints - Data Access Object
JavaWorld: Write once, persist anywhere -
Hello all,
I am trying to a tutorial from a website which were published by Mr Naimesh Patel.
It is a tutorial showing an example of MVC of ABAP Objects.
You can find the URL http://help-abap.blogspot.com/2008/10/abap-objects-design-patterns-model-view_13.html.
I have tried to copy the necessary code including methods and parameters as provided in the article. However while compiling, I got an error Field "O_MODEL->GET_DATA" is unknown.
Based on the article and code, anyone knows how should I resolve this?
What should I define for o_model?
I cant wait for the author to reply my message as I do not know when he will be asnwering me question.
Thanks in advance.Hi all,
After added in the o_model TYPE REF TO zcl_test_model.. I am still having the same error message "Field "O_MODEL->GET_DATA" is unknown.".
*& Report ZTEST_OOP_MVC_ALV
REPORT ZTEST_OOP_MVC_ALV.
START-OF-SELECTION.
* Controller
DATA: lo_control TYPE REF TO zcl_test_control,
o_model TYPE REF TO zcl_test_model.
* Initiate controller
CREATE OBJECT lo_control.
* Get the object from Control
CALL METHOD lo_control->get_object
EXPORTING
if_name = 'ZCL_TEST_MODEL'.
* Model - Business Logic
* Date Range
DATA: r_erdat TYPE RANGE OF vbak-erdat,
la_erdat LIKE LINE OF r_erdat.
la_erdat-sign = 'I'.
la_erdat-option = 'BT'.
la_erdat-low = sy-datum - 10.
la_erdat-high = sy-datum.
APPEND la_erdat TO r_erdat.
* Get data method
CALL METHOD lo_control->o_model->get_data
EXPORTING ir_erdat = r_erdat.
* View - ALV output
DATA: lo_alv TYPE REF TO cl_salv_table,
lx_msg TYPE REF TO cx_salv_msg.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lo_control->o_model->t_vbak ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
*Displaying the ALV
lo_alv->display( ). -
Create ABAP object dynamically
Is it possible to create objects dynamically?
so that the name of the class is set via parameters and also the variables and which class is the superclass?
something like:
fieldsymbols: <a> type any.
data: data_object type ref to object.
create new class type data_object.
data_object-name = 'dynamic'.
data_object-subclass = 'superclass'.
create object <a> like class 'dynamic'
<a>-(method of superclass)( ) etc...
It is not ABAP code, but i hope you know what i mean?
Kindly hear from you!
Anton PierhagenYou can use dynamic reference to instantiate your objects.
Like:
data: lo_ref type ref to object.
create object lo_Ref type ('ZCLASS').
call method lo_ref->('METH_1').
But problem in this design would be that your class & method name is hardcoded and it would be only checked at runtime, not at the design time. To overcome, this you can use the [Factory Method Design pattern|http://help-abap.zevolving.com/2011/10/abap-objects-design-patterns-factory-method/].
Regards,
Naimesh Patel -
Design Pattern and ABAP Objects
Hello Friends,
I would like to know, if ABAP Objects can be used to do pattern oriented programming ?
For example GANG of four has provided almost more then 30 design pattern ( MVC, singelton, Obserable, FACADE,,,etc) can we implement patterns using ABAP ??
Many thanks
Haider SyedHi,
Take a look at the following site:
http://patternshare.org/
It has all the basic patterns from the GOF and a lot more. I can recommend the ones from Martin Fowler but be sure you start with the ones from the GOF.
All patterns are described by using UML so it's very easy to translate them into ABAP OO code.
Regarding your other question. For the observer pattern I used an interface which the SAP had already created if_cm_observer and created my own abstract observable class. The observable class is nearly a 100% copy of the java.util. one
regards
Thomas -
ABAP Object X Design Patterns X Extreme Program
Hi Evebody,
Im postgraduate in Object Oriented Analysis and Programming.
Ive been working with ABAP procedural development for two years and Ive started to work with ABAP Objects has few months.
Id like to get deeply knowledge in my developments skills, could someone tell me if <b>ABAP Object X Designer Patterns X Extreme Program</b> is a good path to follow?
Id like to share material and guides about this topic.
Ive already bought these books to help me.
<b>ABAP Objects</b> - H. Keller; Hardcover <i>(Pre-Order)</i>
<b>Design Patterns Explained</b> - Alan Shalloway
Ill be very grateful with any help.> And do you think these themes are a great combination
> for ABAP development?
Design pattern are very abstract and can be used with any OO programming language. The implementations will differ but the core concepts are always the same.
XP is an agile development process and can also be used with any programming language.
Learning what design pattern are and how to use them is very important in my opinion. Most companies expect that you are familiar and have experience with them.
Extreme Programming (XP) on the other side is different. When I began to explore XP it got me started on how software should be developed in general. Since the concepts behind XP are quite different, it should at least stimulate you to start thinking about how you develop software at the moment and if there might be better ways of doing it.
If you have only time to study one subject go for the design pattern. You might also consider reading the following books if you want to improve your OO coding skills:
<a href="http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672/ref=pd_bbs_sr_1/102-4989641-7820932?ie=UTF8&s=books&qid=1173448197&sr=8-1">Refactoring: Improving the Design of Existing Code (a true classic)</a>
<a href="http://www.amazon.com/Refactoring-Patterns-Addison-Wesley-Signature-Kerievsky/dp/0321213351/ref=pd_bbs_sr_2/102-4989641-7820932?ie=UTF8&s=books&qid=1173448197&sr=8-2">Refactoring to Patterns (Shows how to improve code by introducing design pattern)</a>
cheers
Thomas -
Hi Everyone ,
What are design pattern in Object Oriented ABAP.
How will we know that which pattern suits the particular scenario.
Thanks
SandeepHi,
yes its not free, but its really worth the money.
Other abap specific sources:
http://wiki.sdn.sap.com/wiki/display/ABAP/ABAPObjectsDesignPatterns-ModelViewController%28MVC%29
http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=%28J2EE3417200%29ID0796789650DB21029243082976783901End?blog=/pub/wlg/606
/people/marcelo.ramos/blog/2008/04/30/sapmvc-a-new-mvc-for-classical-abap-dynpro
Greetings,
DSP -
Design Patterns in ABAP.
Hi,
I want to know about the Design Patterns in ABAP.
Regards,
Souravhi sourdi
Below are the list of Design pattern in abap .
Singleton: ensuring single class instantiation
Adapter: making class interfaces compatible
Factory: encapsulating object creation
MVC: decoupling business logic from the view
Facade: providing a simplified interface
Composite: treating individual objects and compositions uniformly
Decorator: forming a dynamic chain of components to be used as one by the client
regards
chinnaiya P -
How to implement Strategy pattern in ABAP Objects?
Hello,
I have a problem where I need to implement different algorithms, depending on the type of input. Example: I have to calculate a Present Value, sometimes with payments in advance, sometimes payment in arrear.
From documentation and to enhance my ABAP Objects skills, I would like to implement the strategy pattern. It sounds the right solution for the problem.
Hence I need some help in implementing this pattern in OO. I have some basic OO skills, but still learning.
Has somebody already implemented this pattern in ABAP OO and can give me some input. Or is there any documentation how to implement it?
Thanks and regards,
TapioKeshav has already outlined required logic, so let me fulfill his answer with a snippet
An Interface
INTERFACE lif_payment.
METHODS pay CHANGING c_val TYPE p.
ENDINTERFACE.
Payment implementations
CLASS lcl_payment_1 DEFINITION.
PUBLIC SECTION.
INTERFACES lif_payment.
ALIASES pay for lif_payment~pay.
ENDCLASS.
CLASS lcl_payment_2 DEFINITION.
PUBLIC SECTION.
INTERFACES lif_payment.
ALIASES pay for lif_payment~pay.
ENDCLASS.
CLASS lcl_payment_1 IMPLEMENTATION.
METHOD pay.
"do something with c_val i.e.
c_val = c_val - 10.
ENDMETHOD.
ENDCLASS.
CLASS lcl_payment_2 IMPLEMENTATION.
METHOD pay.
"do something else with c_val i.e.
c_val = c_val + 10.
ENDMETHOD.
Main class which uses strategy pattern
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
"during main object creation you pass which payment you want to use for this object
METHODS constructor IMPORTING ir_payment TYPE REF TO lif_payment.
"later on you can change this dynamicaly
METHODS set_payment IMPORTING ir_payment TYPE REF TO lif_payment.
METHODS show_payment_val.
METHODS pay.
PRIVATE SECTION.
DATA payment_value TYPE p.
"reference to your interface whcih you will be working with
"polimorphically
DATA mr_payment TYPE REF TO lif_payment.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD constructor.
IF ir_payment IS BOUND.
me->mr_payment = ir_payment.
ENDIF.
ENDMETHOD.
METHOD set_payment.
IF ir_payment IS BOUND.
me->mr_payment = ir_payment.
ENDIF.
ENDMETHOD.
METHOD show_payment_val.
WRITE /: 'Payment value is now ', me->payment_value.
ENDMETHOD.
"hide fact that you are using composition to access pay method
METHOD pay.
mr_payment->pay( CHANGING c_val = payment_value ).
ENDMETHOD. ENDCLASS.
Client application
PARAMETERS pa_pay TYPE c. "1 - first payment, 2 - second
DATA gr_main TYPE REF TO lcl_main.
DATA gr_payment TYPE REF TO lif_payment.
START-OF-SELECTION.
"client application (which uses stategy pattern)
CASE pa_pay.
WHEN 1.
"create first type of payment
CREATE OBJECT gr_payment TYPE lcl_payment_1.
WHEN 2.
"create second type of payment
CREATE OBJECT gr_payment TYPE lcl_payment_2.
ENDCASE.
"pass payment type to main object
CREATE OBJECT gr_main
EXPORTING
ir_payment = gr_payment.
gr_main->show_payment_val( ).
"now client doesn't know which object it is working with
gr_main->pay( ).
gr_main->show_payment_val( ).
"you can also use set_payment method to set payment type dynamically
"client would see no change
if pa_pay = 1.
"now create different payment to set it dynamically
CREATE OBJECT gr_payment TYPE lcl_payment_2.
gr_main->set_payment( gr_payment ).
gr_main->pay( ).
gr_main->show_payment_val( ).
endif.
Regads
Marcin -
Toools to Analysis and Design in ABAP Objects
Hi All?
Somebody knows about an "Analysis and Design Tools" from SAP? I need choice an tools to documentation class in ABAP Objects. Or, is there other like free tools for JAVA?
Is there an Analysis and Design Model recomended from SAP?
Thanks.
Fábio Ferri -
Cosultant - ABAP/XI/ Netweaver.Hi Fabio,
SAP Recommends the use of UML (Unified Modeling Language). They worked with Rational Software in order to provide an external modeling tool to supports SAP's class.
Check this link in order to get more information.
<a href="http://www.sapinsideronline.com/archive/volume_03_(2002)/issue_03_(july-september)/v3i3a11.cfm?session=&promo=iz1321">http://www.sapinsideronline.com/archive/volume_03_(2002)/issue_03_(july-september)/v3i3a11.cfm?session=&promo=iz1321</a>
Regards,
Eric -
Observer Design Pattern: Looking for redesign ABAP OO code example
Hello folks,
I am looking for an example for ABAP OO code that has been redesigned by applying the Observer Design Pattern. I would be very interested in both the code before as well as the code after the pattern is being applied.
Thanks in advance and kind regards, AlexObserver can be implemented using the EVENTS.
I had recently implemented the observer at one of my client's place. I had screen with so many ALVs. One ALV was kind of editable and other were just showing the information of the current row as well as some total information. So, initially I started with the Main ALV and SUB(1 and 2) for other ALVs. Now, when I need to refresh my ALVs based on the main ALV data, I had to explicitly update the data of the each Sub ALV. The code was kind of static and requirement was not yet fixed.
Later on we need to add one more ALV on the same screen. It was easy to change the existing method where I was doing the explicit refresh of each ALV. But I thought of using the Events.
I created an event REFRESH_DETAILS for main ALV. so, when data gets changed (which I was catching by DATA_CHANGED event of ALV), I raise the event.
RAISE EVENT REFRESH_DETAILS
exporting new_data = it_Data.
In Sub ALVs, I created the event handler method to handle the event REFRESH_DETAILS of the main ALV.
methods: handle_refresh_details
for event REFRESH_DETAILS of ZCL_MAIN_ALV.
I also had to register the Handler.
SET HANDLER me->handle_refresh_details FOR ALL INSTANCES.
I'll soon write a post on my [ABAP Help blog|http://help-abap.zevolving.com/] with all the details.
Regards,
Naimesh Patel -
[disc]Design pattern - immutable objects.
I`m working more often with immutable object because it doesn`t cost as much work to keep object consistent. But sometimes an object has to be build or a reference to his child objects has to be set.
eg
class A{
private ArrayList bList = new ArrayList();
public A(){}
public void addB(B b){
bList.add(b);
class B{
private A a;
public B(A a){
this.a = a;
}It`s now more complicated to make a immutable version of A.
My question is how this problem could be solved. One solution is to add an immutable flag that could be set to true if the last B is added. But this couldn`t be checked compile time.
Maybe there is a design pattern for this problem.
I would like to discuss about this problem, so every thought is welcome.I have an Immutable Collection wrapper class that I use when I want to have a Collection be read-only.
If you look at the JavaDoc for AbstractCollection you'll see that the add and remove methods throw UnsuportedOperationException.
So all you have to do is implement the iterator() and size() methods. i.e.
public class ImmutableCollection extends AbstractCollection {
private Collection collection;
* only constructor
public ImmutableCollection(Collection collection) {
this.collection = collection;
* returns the size of the collection
public int size() {
return collection.size();
* returns a non-modifiable iterator over the elements of the collection
public Iterator iterator() {
return new Iterator() {
Iterator iterator = collection.iterator();
public boolean hasNext() {
return iterator.hasNext();
public Object next() {
return iterator.next();
public void remove() {
throw new UnsupportedOperationException();
} -
Flex design pattern for BlazeDS transfer objects
Dear Community,
I have a question regarding the nature of objects transferd from BlazeDS backend to the Flex client.
According to some adobe docs all the presentation logic should be in flex and BlazeDS should provide only services.
The question is what kind of transfer objects should be used? with what level of abstraction?
To make it more clear let's talk about a simple forum application like adobe forums.
I have created a Forum service, which returns a Forum transfer object, which has a List of Threads, with each thread having a List of Messages.
Flex gets the Forum transfer object and does all the presentaiton work.
This is a very nice seperatin of concerns architecture BUT there are two major performance issues:
- when the forum becomes bigger the transfer object will be huge
- the flex will use huge client resources to create the presentation of the forum transfer object.
So my question is what is your strategy/ design pattern for such a problem.
An obvious answer would be create services that include the presentation logic and use transfor objects like ThreadListPage which will include only the first 10 threads.
Thanks in advanceI think you are going to get a few varied types of answers to a general question like this, but I will comment on a few things. First, you should only be transmitting the data that you need to use or display to the user at the time. If this forum was implemented in Flex (I wish) you wouldn't transfer the text for all the threads. You might not transfer the thread text at all (just the subjects), you'd make calls back to the server to fetch that data when and if you need it.
Also, I think you are overestimating the resources required for the Flex "presentation layer". If you think about it, these workstations we have here are pretty idle most of the time when you're at a website. Nowadays there's plenty of processing power just sitting there waiting, so as long as your design isn't flawed the CPU or memory are rarely going to be a bottleneck with Flex.
The way I design, BlazeDS (or GraniteDS etc) should mostly just be "serving data". There is some flexibility available, for example I don't see a problem with putting certain types of business rules (such as a limit on the number of results that can be recieved in a search) within server side code, and validation rules on the Flex side. So there's not too many "industry standards" in Flex yet beyond maybe what's done in the various standard architectures, at least not that I'm aware of.
You might find it beneficial to look into some of the various frameworks/architectures available like Cairngorm, Mate, Swiz, and so on. Learning how they work (looking at examples) would probably answer some of your questions too.
Maybe you are looking for
-
How to change default view in web plugin?
Anyone know how to set a default view in the Reader plugin in Firefox and/or IE? I'm getting sick of having to manually show the task bar and then un-toggle touch mode to get my scroll bar back every time I open a PDF. Thanks!
-
Can't open mail "icon" in control panel office 2013 windows 8.1 (fully patched)
I can't open mail "icon" in control panel office 2013 Home and business & windows 8.1 (fully patched), nothing happens just a short slowdown then this error. Have **replicated** the error on **three different PC's** including 2 x fresh install VM's u
-
Moved library to external HD lost ATV
Had my ATV set and all worked well until I moved my Itunes library and my photos to an external HD. Now I cannot get my ATV to show under my devices. I unclicked 'looking for ATV' box, closed my 7.7 itunes, then opened it again and looked for ATV. op
-
Selection screen - where is my parameter?
Hi all! I've got a curious situation! I added a new parameter in my abap program. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-004. PARAMETERS p_wkzrl TYPE boolean AS CHECKBOX DEFAULT 'X'. SELECTION-SCREEN END OF BLOCK b1a. In our test s
-
How to upload iWeb site to non dot Mac site
I have a personal www address and I am looking to upload my iWeb site to it. Can anyone give me any hints on how to do this??? Thanks!! ~A