Docsity

Programming Language Technologies and Paradigms -Lecture Slides | CMSC 433, Study notes of Programming Languages

Toggle sidebar
bg1
1
CMSC 433 – Programming Language
Technologies and Paradigms
Spring 2007
Façade Pattern
Apr. 05, 2007
2
What is it?
• Frequently, as your programs evolve and develop, they
grow in complexity.
• Furthermore, there may be a number of complicated
subsystems, each of whic h has its own complex interface.
• The Façade pattern allows you to simplify this complexity
by providing a simplified interface to these subsystems.
• This simplification may in some cases reduce the
flexibility of the underlying classes, but usually provides
all the function needed for all but the most sophisticated
users.
• These users can still, of course, access the underlying
classes and methods.
3
For Example
• Java provides a set of classes that connect to
databases using an interface called JDBC.
• You can connect to any database for which the
manufacturer has provided a JDBC connection
class -- almost every database on the market.
• Some databases have direct connections using
JDBC and a few allow connection to ODBC driver
using the JDBC-ODBC bridge class.
4
For Example
• To connect to a database, you use an instance of the Connection class.
• Then, to find out the names of the database tables and fields, you need
to get an instance of the DatabaseMetadata class from the Connection.
• Next, to issue a query, you compose the SQL query string and use the
Connection to create a Statement class.
• By executing the statement, you obtain a ResultSet class, and to find
out the names of the column rows in that ResultSet, you need to obtain
an instance of the ResultsetMetadata class.
• Thus, it can be quite difficult to juggle all of these classes and since
most of the calls to their methods throw Exceptions, the coding can be
messy.
pf3

Partial preview of the text

Download Programming Language Technologies and Paradigms -Lecture Slides | CMSC 433 and more Study notes Programming Languages in PDF only on Docsity!

1

CMSC 433 – Programming Language

Technologies and Paradigms

Spring 2007

Façade Pattern Apr. 05, 2007

What is it?

grow in complexity.Frequently, as your programs evolve and develop, they

subsystems, each of which has its own complex interface.Furthermore, there may be a number of complicated

by providing a simplified interface to these subsystems.The Façade pattern allows you to simplify this complexity

users.all the function needed for all but the most sophisticatedflexibility of the underlying classes, but usually providesThis simplification may in some cases reduce the

classes and methods.These users can still, of course, access the underlying

3

For Example

databases using an interface called JDBC.Java provides a set of classes that connect to

class -- almost every database on the market.manufacturer has provided a JDBC connectionYou can connect to any database for which the

using the JDBC-ODBC bridge class.JDBC and a few allow connection to ODBC driverSome databases have direct connections using

For Example

To connect to a database, you use an instance of the Connection class.

to get an instance of the DatabaseMetadata class from the Connection.Then, to find out the names of the database tables and fields, you need

Connection to create a Statement class.Next, to issue a query, you compose the SQL query string and use the

an instance of the ResultsetMetadata class.out the names of the column rows in that ResultSet, you need to obtainBy executing the statement, you obtain a ResultSet class, and to find

messy.most of the calls to their methods throw Exceptions, the coding can beThus, it can be quite difficult to juggle all of these classes and since

5

In Pictures!

A Facade

(note the lowercase “r”), we can build a much more usable system.By designing a Façade consisting of a Database class and a resultSet class

7

Database Class

resultSet