Java Reference
In-Depth Information
There is a design pattern that describes what we are trying to achieve here: the Façade
pattern. The English meaning of the word “façade” is the front face of something, typically a
building. So we might refer to the front of a shop or building as its façade: the view of the
building that the average user gets to see. In the same way, we can think of the DvdDatabase as
the front face, or façade, shown to external users, hiding the classes that external users may
not need to know about.
Note Although using a façade does not stop us from using the word “and” in our description of what the
class does, it does change the class itself so that the faced class is not providing all the functionality; it is
handing off to the other classes behind the scene.
Our DvdDatabase class is therefore very simple. We start by creating references to the
classes that do the real work:
package sampleproject.db;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.regex.PatternSyntaxException;
public class DvdDatabase implements DBClient {
private static ReservationsManager reservationsManager
= new ReservationsManager();
private static DVDFileAccess database = null;
public DvdDatabase() throws FileNotFoundException, IOException {
this(System.getProperty("user.dir"));
}
public DvdDatabase(String dbPath) throws FileNotFoundException, IOException {
database = new DvdFileAccess(dbPath);
}
We now have to define our constructors for DvdDatabase . Since the instructions for our
sample project do not specify how the DvdDatabase constructor should appear, we have some
flexibility. This prompts two primary concerns:
1. What parameters should we use for the constructor?
2. What exceptions, if any, should be thrown from the constructors?
Regarding the parameters, we have to consider how this class will be used. We know that
it might be used in a stand-alone application, and for that purpose it might be handy not to
Search WWH ::




Custom Search