Scenario

[Previous] [Next]

A common approach to improving the debugging process of an application is to include logging functionality. Let's assume you're concerned about logging errors that the application raises or captures. You want the flexibility of logging the errors to any medium, such as a text file, a window, e-mail, the Microsoft Windows 2000 Event Viewer log, or any imaginable media that become available. Programming support for various media directly into the application is definitely not a scalable solution. You can solve this problem by using the Event Service design pattern to incorporate a logging mechanism into the application. This mechanism decouples the application that publishes the message from the subscriber—in this case, the various media that receive the message. Figure 13-1 illustrates a plausible object diagram of such an application.

Notice the reference to a LogEventService object, which facilitates the existence of a LogEventChannel object. The application also maintains a reference to the LogPublisher object, which is provided by the LogEventService object. Additionally, the TextFile, Email, and WindowsMonitor objects are registered subscribers to the LogEventChannel object for the application, and the application is oblivious to their existence. The LogEventChannel object determines the registration policy. Your application simply logs messages by invoking the LogPublisher object's LogMessage method. The LogPublisher object in turn submits the message to the LogEventChannel object that ultimately notifies the subscribers (TextFile, Email, and WindowsMonitor).

click to view at full size.

Figure 13-1. Application log event service object model.



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net