The intent behind the Observer Design Pattern is to define a dependecy between objects so that when main object changes its state, all the dependent objects are notified. Its upto the dependent objects to update themselves or ignore the notification.
Design time consideration:
- In the main object, AKA Subject, create a Event. Also add create a signature to the event.
- Create class with Event Handler method for the event of the Subject.
- Inherit the Subclasses for different behavior. Redefine the event handler method for which any behavior is required.
- Register the event handler using the statement SET EVENT HANDLER ... FOR O_SUBJECT.Follow this ABAP Objects Design Patterns – Observer for more information (NOTE: Outside SDN Link).
Case Study: Usage of Observer in real world
Smaller version of the demo which shows the real world example of the Observer while working with Multiple ALVs. Follow Case Study: Observer Design Pattern Usage for more details. (NOTE: Outside SDN Link).