Home > Articles > Software Development & Management > UML

  • Print
  • + Share This
Like this article? We recommend

Running the Code

So let's put it all together in Listing 9, which is an excerpt from the main() function.

Listing 9 Instantiating the Subject and its Observers

    OperationList* myOperationList = new OperationList();
    NetOperationViewer* myNetOperationViewer = 
       new NetOperationViewer(myOperationList);

    NetOperationPercentViewer* myNetOperationViewer2 = 
       new NetOperationPercentViewer(myOperationList);

    //Now the asynchronous process updates the operation status
    myOperationList->UpdateOperations("DB Backup 10% Complete\0");

    //Now the asynchronous process updates the other operation status
    myOperationList->UpdateOperations("DB Backup 50% Complete\0");

The first line of Listing 9 illustrates the instantiation of a subject. This is the data generator and is referenced by the name myOperationList. In the second line, you see the first observer followed by the second observer on the next line.

The fourth line illustrates an operation update—the text indicates that we have reached 10% completion. Both observers will register this information, as shown in Listing 1. A further operation update is seen at the bottom of Listing 9; again, this is reflected in the two observers.

  • + Share This
  • 🔖 Save To Your Account