Pattern 1 - Public interface, private implementation, and factory class

Separate the public API from the internal encapsulated implementation (we've already seen this strategy implemented in the sorting utility module of the address book viewer application earlier in the book). Also, expose a factory API method that creates new instances of the interface.

Here's how it works:

  • The exported types are interfaces or abstract classes that are as lightweight as possible.
  • The classes that contain the actual logic implement the interfaces in the exported packages. These types are not exported. Thus, all the implementation details are safely hidden away.
  • There are factory classes in the exposed packages that form the APIs. These create a new instance of the right implementation class. The return types of these factory APIs deal with interfaces only.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.173.242