Defining the Notify operation

About this task

The Notify operation needs a list of observers to notify. Make the following changes in the diagram:

Procedure

  1. To the right of the SDM class, draw another class and change the generated name to be alarmObserver.
  2. To the right of the new alarmObserver class, draw a policeObserver class. Your diagram resembles this example.
  3. The Notify operation also needs to call an Act operation for the observers. Follow these steps to add it:
    1. In the browser, right-click the alarmObserver to display the menu and select Features.
    2. Select the Operations tab to add the new operation.
    3. Select PrimitiveOperation and name it Act. Assign it "Public" Visibility and a "Void" Return Type.
    4. Click OK to save.
    5. Repeat steps 1 - 4 to create the policeObserver class.
    6. Then make the Act operation display in the diagram. Your diagram resembles this example.
  4. The Act operation needs to be implemented with "activating alarm" or "calling the police." Follow these steps to add the necessary implementations:
    1. In the browser, right-click Act() under the alarmObserver.
    2. Select the Features option and then the Implementation tab.
    3. Type the following code in the Implementation area:
      below.omcout << "Activating alarm..." << omendl;
    4. Click OK to save.
    5. In the browser, right-click Act() under the policeObserver.
    6. Select the Features option and then the Implementation tab.
    7. Type the following code in the Implementation area:
      omcout << "Calling the police..." << omendl;
    8. Click OK.

Feedback