7. Adapter mode

  • First, the role
    • Target (destination interface): The interface adapter's implementation
    • Adapter (fitter): class that implements the target interface
    • The Adaptee (adapted): class is used by the adaptation
  • Second, the application scene
    • Use an existing class, and its interface does not meet your needs
    • Can create a reusable class, this class may not be related or other unforeseen class work
  • Third, examples
    • FIG -1 Target is the target interface, M5DataLineAdapter adaptation class is the interface to achieve the goal, M5DataLineAdapter inheritance M4DataLine, where M4DataLine was adapted by, M5DataLineAdapter's actual call is adapted to connection1 M4DataLine connection method in the interface the method, in fact, can also here to use a combination of connection1 M4DataLine class, according to try to use synthetic / polymeric, try not to use the principle of inheritance, where the examples using a combination of the principles of better, i.e. FIG -1 the adapter implementation class M5DataLineAdapter1
    • Code Address: https://github.com/lanhei/DesignPattern/tree/master/src/com/lanhei/patterns/adapter

      figure 1

Guess you like

Origin www.cnblogs.com/zhongj/p/11275348.html