When you need to adapt your code,you may find that the client developer planed well for such circumstances. This is evident when the develper provides an interface that defines the services that the client code needs, as the example in Figure 3.1 shows A client class makes calls to a RequiredMethod() method that is declared in an interface.You may have found an existing class with a method that can fullfill the client's needs,with a name such as UsefulMethod(). You can adapt the existing class to meet the client's need by writing a class that exitend Existing Class,Implements RequiredInterface, and overrides RequiredMethod() so that it delegates its requests to usefulMethod().
Adatpter
最新推荐文章于 2021-08-01 17:46:18 发布