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
  • PrintPrint

Base Classes

Some interfaces have many methods, and implementing classes must override all the methods. This can be a tedious task if only some of the methods are actually used in the code. For this reason, you can create a generic implementation class that overrides the methods in an interface with default code. An implementing class then extends the generic class and overrides only methods it wants to change. This kind of generic class, often called a base class, is handy because it helps you code faster.

For example, the javax.servlet.Servlet interface is the interface that must be implemented by all servlet classes. This interface has five methods: init, service, destroy, getServletConfig, getServletInfo. Of the five, only the service method is always implemented by servlet classes. The init method is implemented occasionally, but the rest are rarely used. Despite the fact, all implementing classes must provide implementation for all five methods. What a chore this would be for servlet programmers.


  

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
  • PrintPrint