Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Observer Design Pattern: Looking for redesign ABAP OO code example

Former Member
0 Kudos

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, Alex

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Observer 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

6 REPLIES 6

Former Member
0 Kudos

Hi,

plz follow link, may help u:

<External link removed>

thanks & regards.

Moderator Message: Don't spoonfeed.

Edited by: Suhas Saha on Oct 27, 2011 11:06 AM

0 Kudos

Hi Suhas Saha,

thanks for your answer. It helps but unfortunately does not give me the complete truth ). What I am looking for is a concrete real-world example for ABAP code with a "bad" design that has then be reengineered to a "good" design. Hence, I need the situation before and after the observer design pattern is being applied.

Does anybody know such an example from standard R/3 code?

Thanks and kind regards, Alexander

naimesh_patel
Active Contributor
0 Kudos

Observer 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

0 Kudos

Hi Samel,

thanks a lot for this very useful and helpful example! It would be great if you could provide me the complete example. That is exactly what I am looking for. In case you are interested, I can provide you a paper of mine in which my research work is reflected.

Kind regards, Alex

0 Kudos

As promised, I have tried to write two post:

Concept -- [ABAP Objects Design Patterns u2013 Observer|http://help-abap.zevolving.com/2011/10/abap-objects-design-patterns-%e2%80%93-observer/]

Real Time example which I mentioned above -- [Case Study: Observer Design Pattern Usage|http://help-abap.zevolving.com/2011/11/case-study-observer-design-pattern-usage/]

Regards,

Naimesh Patel

0 Kudos

Hi Naimesh,

thank you very much for this fast delivery of the complete example.

It looks very fine and I think that it will fit perfectly in my research work. I will have a look asap on it and get back to you with feedback and the results of the applied methodology that hopefully work.

Kind regards, Alex