Design Patterns Facade (exterior Explorer Manager)
Itabashi Azeri 2002/4/6 / (Reprinted Please keep)
model real book system, a set of interfaces to provide a consistent interface.
Facade of a typical JDBC application is the database application, the following example operation of the database:
public class DBCompare {
Connection conn = null;
PreparedStatement prep = null;
ResultSet rset = null;
try {
Class.forName ( . setString (1, getString (
prep.close ();
conn.close ();
}
}
Jsp on the case is the most common methods of database operations.
in the application, often the need for database operations, each writing a section of code above is certainly more trouble, you need to change some of them extracted, made into an interface, which introduced the facade the appearance of objects. If in the future we replace Class.forName < driver> is also very convenient, such as changing from a Mysql database to the Oracle database, as long as the replacement driver facade interface can.
we made a Facade interface, use the interface to the example program can be changed as follows:
public class DBCompare {
String sql =
prep.setString (1, println (rset.getString (close ();
mysql = null;
}
}
can see is very simple, all programs are used to change the database access interface, reducing system complexity and increase flexibility.
If we want to use connection pooling, but also for the facade as long as the interface can change.
can be seen from the above, facade really is a relationship between streamline the system to reduce coupling between systems, a commonly used method, you may have unknowingly used, although not sure it is facade.
how the specific project design patterns in applications, see
No comments:
Post a Comment