concept implementation in category iBatis

appears as: implementation, implementation, implementations, n implementation, implementations, The implementation
iBatis in Action

This is an excerpt from Manning's book iBatis in Action.

The role of the abstraction layer is to provide a consistent and meaningful interface to the persistence layer. It is a set of classes and methods that act as a façade to the persistence implementation details. Methods in the abstraction layer should never require any implementation-specific parameters, nor should it return any values or throw any exceptions that are exclusive to the persistence implementation. With a proper abstraction layer in place, the entire persistence approach—including both the persistence API and the storage infrastructure—should be able to change without modifications to the abstraction layer or any of the layers that depend on it. There are patterns that can help with the implementation of a proper abstraction layer, the most popular of which is the Data Access Objects (DAO) pattern. Some frameworks, including iBATIS, implement this pattern for you. We discuss the iBATIS DAO framework in chapter 11.

In that example, what is the implementation? We neither know nor care, because the DaoFactory handles it for us. All we care about is that this DaoFactory item returns an object that implements the AccountDao interface. We do not care if it uses LDAP, JDBC, or smoke and mirrors to make it happen, as long as it does.

11.4.1. Separating interface from implementation

The reason you want to separate your DAO into an interface and an implementation is twofold. First, you want to be able to replace the implementation if you have to support a different type of data access. Second, separation makes testing much simpler and faster because you can plug in a mock DAO instead of working with the database.