Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 9. Interfaces > The Case for Interfaces

9.1. The Case for Interfaces

Suppose we're creating a logging class, Logger, that reports status messages ("log entries") for a program as it runs. Many classes receive the Logger's status messages and respond to them in different ways. For example, one class, LogUI, displays log messages on screen; another class, LiveLog, alerts a live support technician via a networked administration tool; yet another class, LogTracker, adds log messages to a database for statistics tracking. To receive log messages, each class defines an update( ) method. To send a message to objects of each interested class, the Logger class invokes the update( ) method.

That all seems logical enough so far, but what happens if we forget to define the update( ) method in the LogUI class? The status message will be sent, but LogUI objects won't receive it. We need a way to guarantee that each log recipient defines the update( ) method.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint